From: Tim Wiederhake Date: Tue, 18 May 2021 15:04:46 +0000 (+0200) Subject: virDomainDiskDefGeometryParse: Use virXMLProp* X-Git-Tag: v7.4.0-rc1~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b1cb2934ed9c8f369b50d76be0a59259f5aff92;p=thirdparty%2Flibvirt.git virDomainDiskDefGeometryParse: Use virXMLProp* This strictens the parser to disallow negative values (interpreted as `UINT_MAX + value + 1`) for attributes `cyls`, `heads` and `secs`. Allowing negative numbers to be interpreted this way makes no sense for these attributes. Signed-off-by: Tim Wiederhake Reviewed-by: Laine Stump --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f55117e849..bfcc56ca9e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8815,45 +8815,21 @@ static int virDomainDiskDefGeometryParse(virDomainDiskDef *def, xmlNodePtr cur) { - g_autofree char *tmp = NULL; - - if ((tmp = virXMLPropString(cur, "cyls"))) { - if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.cylinders) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid geometry settings (cyls)")); - return -1; - } - VIR_FREE(tmp); - } + if (virXMLPropUInt(cur, "cyls", 10, VIR_XML_PROP_NONE, + &def->geometry.cylinders) < 0) + return -1; - if ((tmp = virXMLPropString(cur, "heads"))) { - if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.heads) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid geometry settings (heads)")); - return -1; - } - VIR_FREE(tmp); - } + if (virXMLPropUInt(cur, "heads", 10, VIR_XML_PROP_NONE, + &def->geometry.heads) < 0) + return -1; - if ((tmp = virXMLPropString(cur, "secs"))) { - if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.sectors) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid geometry settings (secs)")); - return -1; - } - VIR_FREE(tmp); - } + if (virXMLPropUInt(cur, "secs", 10, VIR_XML_PROP_NONE, + &def->geometry.sectors) < 0) + return -1; - if ((tmp = virXMLPropString(cur, "trans"))) { - int value; - if ((value = virDomainDiskGeometryTransTypeFromString(tmp)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid translation value '%s'"), - tmp); - return -1; - } - def->geometry.trans = value; - } + if (virXMLPropEnum(cur, "trans", virDomainDiskGeometryTransTypeFromString, + VIR_XML_PROP_NONZERO, &def->geometry.trans) < 0) + return -1; return 0; }