mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
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 <twiederh@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
ef18ca1c06
commit
1b1cb2934e
@ -8815,45 +8815,21 @@ static int
|
|||||||
virDomainDiskDefGeometryParse(virDomainDiskDef *def,
|
virDomainDiskDefGeometryParse(virDomainDiskDef *def,
|
||||||
xmlNodePtr cur)
|
xmlNodePtr cur)
|
||||||
{
|
{
|
||||||
g_autofree char *tmp = NULL;
|
if (virXMLPropUInt(cur, "cyls", 10, VIR_XML_PROP_NONE,
|
||||||
|
&def->geometry.cylinders) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if ((tmp = virXMLPropString(cur, "cyls"))) {
|
if (virXMLPropUInt(cur, "heads", 10, VIR_XML_PROP_NONE,
|
||||||
if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.cylinders) < 0) {
|
&def->geometry.heads) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
return -1;
|
||||||
_("invalid geometry settings (cyls)"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((tmp = virXMLPropString(cur, "heads"))) {
|
if (virXMLPropUInt(cur, "secs", 10, VIR_XML_PROP_NONE,
|
||||||
if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.heads) < 0) {
|
&def->geometry.sectors) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
return -1;
|
||||||
_("invalid geometry settings (heads)"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((tmp = virXMLPropString(cur, "secs"))) {
|
if (virXMLPropEnum(cur, "trans", virDomainDiskGeometryTransTypeFromString,
|
||||||
if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.sectors) < 0) {
|
VIR_XML_PROP_NONZERO, &def->geometry.trans) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
return -1;
|
||||||
_("invalid geometry settings (secs)"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user