]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainChrSourceReconnectDefParseXML: Use virXMLProp*
authorTim Wiederhake <twiederh@redhat.com>
Tue, 18 May 2021 15:04:47 +0000 (17:04 +0200)
committerLaine Stump <laine@redhat.com>
Tue, 18 May 2021 16:27:13 +0000 (12:27 -0400)
This strictens the parser to disallow negative values (interpreted as
`UINT_MAX + value + 1`) for attribute `timeout`. Allowing negative
numbers to be interpreted this way makes no sense for this attribute.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/conf/domain_conf.c

index bfcc56ca9ef5153bc36bcdac2a537edd138c4d6b..a5514660ccc1c847230a7526096005a844c08c16 100644 (file)
@@ -10093,39 +10093,20 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDef *def,
                                        xmlNodePtr node,
                                        xmlXPathContextPtr ctxt)
 {
-    int tmpVal;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     xmlNodePtr cur;
-    g_autofree char *tmp = NULL;
 
     ctxt->node = node;
 
     if ((cur = virXPathNode("./reconnect", ctxt))) {
-        if ((tmp = virXMLPropString(cur, "enabled"))) {
-            if ((tmpVal = virTristateBoolTypeFromString(tmp)) < 0) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("invalid reconnect enabled value: '%s'"),
-                               tmp);
-                return -1;
-            }
-            def->enabled = tmpVal;
-            VIR_FREE(tmp);
-        }
+        if (virXMLPropTristateBool(cur, "enabled", VIR_XML_PROP_NONE,
+                                   &def->enabled) < 0)
+            return -1;
 
         if (def->enabled == VIR_TRISTATE_BOOL_YES) {
-            if ((tmp = virXMLPropString(cur, "timeout"))) {
-                if (virStrToLong_ui(tmp, NULL, 10, &def->timeout) < 0) {
-                    virReportError(VIR_ERR_XML_ERROR,
-                                   _("invalid reconnect timeout value: '%s'"),
-                                   tmp);
-                    return -1;
-                }
-            } else {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("missing timeout for chardev with "
-                                 "reconnect enabled"));
+            if (virXMLPropUInt(cur, "timeout", 10, VIR_XML_PROP_REQUIRED,
+                               &def->timeout) < 0)
                 return -1;
-            }
         }
     }