[PATCH 21/43] util: xml: Disallow aliasing of negative numbers in virXPathUInt

Peter Krempa posted 43 patches 3 years, 3 months ago
[PATCH 21/43] util: xml: Disallow aliasing of negative numbers in virXPathUInt
Posted by Peter Krempa 3 years, 3 months ago
Passing negative number as an alias for the max value is an anti-feature
we unfortunately allowed in virsh, but luckily never encouraged in the
XML.

Refuse numbers with negative sign when parsing unsigned int from
XPaths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/util/virxml.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index a47a5d49fc..d80a69f163 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -253,7 +253,7 @@ virXPathUIntBase(const char *xpath,
     if (!(obj = virXPathEvalString(xpath, ctxt)))
         return -1;

-    if (virStrToLong_ui((char *) obj->stringval, NULL, base, value) < 0)
+    if (virStrToLong_uip((char *) obj->stringval, NULL, base, value) < 0)
         return -2;

     return 0;
-- 
2.37.3
Re: [PATCH 21/43] util: xml: Disallow aliasing of negative numbers in virXPathUInt
Posted by Ján Tomko 3 years, 3 months ago
On a Monday in 2022, Peter Krempa wrote:
>Passing negative number as an alias for the max value is an anti-feature
>we unfortunately allowed in virsh, but luckily never encouraged in the
>XML.
>
>Refuse numbers with negative sign when parsing unsigned int from
>XPaths.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/util/virxml.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano