]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainSoundDefParseXML: Use virXMLProp*
authorTim Wiederhake <twiederh@redhat.com>
Tue, 27 Apr 2021 11:12:53 +0000 (13:12 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 3 May 2021 09:17:40 +0000 (11:17 +0200)
This strictens the parser to disallow negative values (interpreted as
`UINT_MAX + value + 1`) for attribute `id`.

`id` must be greater than 0 and does not benefit from being referable as
e.g. "-7" for host audio backend 4294967289, as this value is distinctly
out of range for normal use.

Additionally, this patch fixes a use of NULL string with printf's %s
modifier if the `model` attribute is absent.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 305ed17867690d26f0ece24755f7c34dac3b2e98..1e88b6370b2e2bdd12d9844ea250eb2e3bac058d 100644 (file)
@@ -13212,20 +13212,14 @@ virDomainSoundDefParseXML(virDomainXMLOption *xmlopt,
 {
     virDomainSoundDef *def;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    g_autofree char *model = NULL;
-    int modelval;
     xmlNodePtr audioNode;
 
     def = g_new0(virDomainSoundDef, 1);
     ctxt->node = node;
 
-    model = virXMLPropString(node, "model");
-    if ((modelval = virDomainSoundModelTypeFromString(model)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown sound model '%s'"), model);
+    if (virXMLPropEnum(node, "model", virDomainSoundModelTypeFromString,
+                       VIR_XML_PROP_REQUIRED, &def->model) < 0)
         goto error;
-    }
-    def->model = modelval;
 
     if (virDomainSoundModelSupportsCodecs(def)) {
         int ncodecs;
@@ -13254,19 +13248,10 @@ virDomainSoundDefParseXML(virDomainXMLOption *xmlopt,
 
     audioNode = virXPathNode("./audio", ctxt);
     if (audioNode) {
-        g_autofree char *tmp = NULL;
-        tmp = virXMLPropString(audioNode, "id");
-        if (!tmp) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("missing audio 'id' attribute"));
-            goto error;
-        }
-        if (virStrToLong_ui(tmp, NULL, 10, &def->audioId) < 0 ||
-            def->audioId == 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid audio 'id' value '%s'"), tmp);
+        if (virXMLPropUInt(audioNode, "id", 10,
+                           VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+                           &def->audioId) < 0)
             goto error;
-        }
     }
 
     if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags) < 0)