1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

conf: report errors when parsing video resolution

The current code doesn't properly handle errors when parsing a video
device's resolution.  We were returning a NULL structure for the case
where 'x' or 'y' were missing. But for the other error cases, we were
logging an error (virReportError()), but still returning an
under-specified structure. That under-specified structure was used by
the calling function rather than properly reporting an error.

This patch changes the parse function to return NULL on any parsing
error and changes the calling function to report an error when NULL is
returned.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Jonathon Jongsma 2019-11-14 15:59:15 -06:00 committed by Cole Robinson
parent 333cca0bfc
commit 754e4c24ec

View File

@ -15309,24 +15309,26 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr node)
x = virXMLPropString(node, "x"); x = virXMLPropString(node, "x");
y = virXMLPropString(node, "y"); y = virXMLPropString(node, "y");
if (!x || !y) if (!x || !y) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("missing values for resolution"));
return NULL; return NULL;
}
def = g_new0(virDomainVideoResolutionDef, 1); def = g_new0(virDomainVideoResolutionDef, 1);
if (virStrToLong_uip(x, NULL, 10, &def->x) < 0) { if (virStrToLong_uip(x, NULL, 10, &def->x) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("cannot parse video x-resolution '%s'"), x); _("cannot parse video x-resolution '%s'"), x);
goto cleanup; return NULL;
} }
if (virStrToLong_uip(y, NULL, 10, &def->y) < 0) { if (virStrToLong_uip(y, NULL, 10, &def->y) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("cannot parse video y-resolution '%s'"), y); _("cannot parse video y-resolution '%s'"), y);
goto cleanup; return NULL;
} }
cleanup:
return g_steal_pointer(&def); return g_steal_pointer(&def);
} }
@ -15415,8 +15417,10 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
virXMLNodeNameEqual(child, "acceleration")) virXMLNodeNameEqual(child, "acceleration"))
def->accel = virDomainVideoAccelDefParseXML(child); def->accel = virDomainVideoAccelDefParseXML(child);
if (def->res == NULL && if (def->res == NULL &&
virXMLNodeNameEqual(child, "resolution")) virXMLNodeNameEqual(child, "resolution")) {
def->res = virDomainVideoResolutionDefParseXML(child); if ((def->res = virDomainVideoResolutionDefParseXML(child)) == NULL)
goto error;
}
} }
child = child->next; child = child->next;
} }