]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Always use 'string()' conversion with virXPath(U)LongLong
authorPeter Krempa <pkrempa@redhat.com>
Tue, 4 Oct 2022 15:06:14 +0000 (17:06 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Nov 2022 12:07:20 +0000 (13:07 +0100)
When the 'string()' conversion is used the number is parsed inside
libvirt by our internal helpers which work on integers in contrast to
when 'number()' is used and libxml2 uses a 'double' variable internally.

On the upper extremes of the 64 bit variables the double precision
variable doesn't have enough precision to represent each distinct
integer and thus could cause problems.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c
src/conf/node_device_conf.c
src/conf/storage_conf.c

index 7dba65cfebe0d8d555411706578e6a7ce781064b..7984a15c46b6180e08596cdd56974a73f955e205 100644 (file)
@@ -18103,10 +18103,10 @@ virDomainDefClockParse(virDomainDef *def,
         break;
 
     case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE:
-        if (virXPathLongLong("number(./clock/@adjustment)", ctxt,
+        if (virXPathLongLong("string(./clock/@adjustment)", ctxt,
                              &def->clock.data.variable.adjustment) < 0)
             def->clock.data.variable.adjustment = 0;
-        if (virXPathLongLong("number(./clock/@adjustment0)", ctxt,
+        if (virXPathLongLong("string(./clock/@adjustment0)", ctxt,
                              &def->clock.data.variable.adjustment0) < 0)
             def->clock.data.variable.adjustment0 = 0;
         tmp = virXPathString("string(./clock/@basis)", ctxt);
@@ -18132,7 +18132,7 @@ virDomainDefClockParse(virDomainDef *def,
         break;
 
     case VIR_DOMAIN_CLOCK_OFFSET_ABSOLUTE:
-        if (virXPathULongLong("number(./clock/@start)", ctxt,
+        if (virXPathULongLong("string(./clock/@start)", ctxt,
                               &def->clock.data.starttime) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("missing 'start' attribute for clock with offset='absolute'"));
index b882fcfbe8418997434ed240e0fa9561ff938d48..c683c0d269dfbe0c2f3316757cfb7671cd955f5e 100644 (file)
@@ -1463,7 +1463,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
             storage->media_label = virXPathString("string(./media_label[1])", ctxt);
 
             val = 0;
-            if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def,
+            if (virNodeDevCapsDefParseULongLong("string(./media_size[1])", ctxt, &val, def,
                                                 _("no removable media size supplied for '%s'"),
                                                 _("invalid removable media size supplied for '%s'")) < 0) {
                 return -1;
@@ -1481,7 +1481,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
 
     if (!(storage->flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) {
         val = 0;
-        if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def,
+        if (virNodeDevCapsDefParseULongLong("string(./size[1])", ctxt, &val, def,
                                             _("no size supplied for '%s'"),
                                             _("invalid size supplied for '%s'")) < 0)
             return -1;
index 72c53872cb268d6e8c7fd802dd87f1848b5a0c8c..f5a9636ce2235abb59dc8fed98bb243ee5a722f8 100644 (file)
@@ -720,7 +720,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
         perms->uid = (uid_t) -1;
     } else {
         /* We previously could output -1, so continue to parse it */
-        if (virXPathLongLong("number(./owner)", ctxt, &val) < 0 ||
+        if (virXPathLongLong("string(./owner)", ctxt, &val) < 0 ||
             ((uid_t)val != val &&
              val != -1)) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -735,7 +735,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
         perms->gid = (gid_t) -1;
     } else {
         /* We previously could output -1, so continue to parse it */
-        if (virXPathLongLong("number(./group)", ctxt, &val) < 0 ||
+        if (virXPathLongLong("string(./group)", ctxt, &val) < 0 ||
             ((gid_t) val != val &&
              val != -1)) {
             virReportError(VIR_ERR_XML_ERROR, "%s",