From: Peter Krempa Date: Tue, 4 Oct 2022 15:06:14 +0000 (+0200) Subject: conf: Always use 'string()' conversion with virXPath(U)LongLong X-Git-Tag: v8.10.0-rc1~256 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8525ac4b839ef8112397ef262f75d7fe742bd683;p=thirdparty%2Flibvirt.git conf: Always use 'string()' conversion with virXPath(U)LongLong 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 Reviewed-by: Ján Tomko --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7dba65cfeb..7984a15c46 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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'")); diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index b882fcfbe8..c683c0d269 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -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; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 72c53872cb..f5a9636ce2 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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",