]> xenbits.xensource.com Git - libvirt.git/commitdiff
xml: Make sure virXpathNodeSet always sets an error
authorCole Robinson <crobinso@redhat.com>
Thu, 12 May 2011 19:45:22 +0000 (15:45 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 13 May 2011 14:32:52 +0000 (10:32 -0400)
And update callers to actually respect the error

src/conf/domain_conf.c
src/conf/interface_conf.c
src/conf/network_conf.c
src/conf/node_device_conf.c
src/conf/storage_conf.c
src/conf/storage_encryption_conf.c
src/qemu/qemu_domain.c
src/test/test_driver.c
src/util/xml.c

index d3efec624975f6b9ad3cfdec545fe59393c2bfe5..9ab9a5a498506283dfc77ea4d0afb1310549c996 100644 (file)
@@ -5228,8 +5228,6 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
 
     /* analysis of the boot devices */
     if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract boot device"));
         goto cleanup;
     }
 
@@ -5517,8 +5515,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
         def->cputune.shares = 0;
 
     if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract vcpupin nodes"));
         goto error;
     }
 
@@ -5613,8 +5609,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     }
 
     if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("failed to parse timers"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->clock.timers, n) < 0)
@@ -5742,8 +5736,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the disk devices */
     if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract disk devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->disks, n) < 0)
@@ -5762,8 +5754,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the controller devices */
     if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract controller devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->controllers, n) < 0)
@@ -5780,8 +5770,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the filesystems */
     if ((n = virXPathNodeSet("./devices/filesystem", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract filesystem devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->fss, n) < 0)
@@ -5798,8 +5786,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the network devices */
     if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract network devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->nets, n) < 0)
@@ -5820,8 +5806,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the smartcard devices */
     if ((n = virXPathNodeSet("./devices/smartcard", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract smartcard devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->smartcards, n) < 0)
@@ -5840,8 +5824,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the character devices */
     if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract parallel devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->parallels, n) < 0)
@@ -5868,8 +5850,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     VIR_FREE(nodes);
 
     if ((n = virXPathNodeSet("./devices/serial", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract serial devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->serials, n) < 0)
@@ -5926,8 +5906,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     }
 
     if ((n = virXPathNodeSet("./devices/channel", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract channel devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->channels, n) < 0)
@@ -5967,8 +5945,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the input devices */
     if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract input devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->inputs, n) < 0)
@@ -6001,8 +5977,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the graphics devices */
     if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract graphics devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->graphics, n) < 0)
@@ -6044,8 +6018,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the sound devices */
     if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract sound devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->sounds, n) < 0)
@@ -6062,8 +6034,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the video devices */
     if ((n = virXPathNodeSet("./devices/video", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract video devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->videos, n) < 0)
@@ -6102,8 +6072,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     /* analysis of the host devices */
     if ((n = virXPathNodeSet("./devices/hostdev", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract host devices"));
         goto error;
     }
     if (n && VIR_ALLOC_N(def->hostdevs, n) < 0)
@@ -6122,8 +6090,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     /* analysis of the watchdog devices */
     def->watchdog = NULL;
     if ((n = virXPathNodeSet("./devices/watchdog", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract watchdog devices"));
         goto error;
     }
     if (n > 1) {
@@ -6144,8 +6110,6 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     /* analysis of the memballoon devices */
     def->memballoon = NULL;
     if ((n = virXPathNodeSet("./devices/memballoon", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("cannot extract memory balloon devices"));
         goto error;
     }
     if (n > 1) {
@@ -6312,8 +6276,6 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
     obj->pid = (pid_t)val;
 
     if ((n = virXPathNodeSet("./taint", ctxt, &nodes)) < 0) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("failed to parse taint flags"));
         goto error;
     }
     for (i = 0 ; i < n ; i++) {
index 2c051ea00997d1fe74e5b41b02ca2dd9d09dcd42..f3848bdaab7ecd1b2234db63c768908a80fd2a3e 100644 (file)
@@ -424,7 +424,10 @@ virInterfaceDefParseIfAdressing(virInterfaceDefPtr def,
     save = ctxt->node;
 
     nProtoNodes = virXPathNodeSet("./protocol", ctxt, &protoNodes);
-    if (nProtoNodes <= 0) {
+    if (nProtoNodes < 0)
+        goto error;
+
+    if (nProtoNodes == 0) {
         /* no protocols is an acceptable outcome */
         return 0;
     }
@@ -495,8 +498,6 @@ virInterfaceDefParseBridge(virInterfaceDefPtr def,
     bridge = ctxt->node;
     nbItf = virXPathNodeSet("./interface", ctxt, &interfaces);
     if (nbItf < 0) {
-        virInterfaceReportError(VIR_ERR_XML_ERROR,
-                                "%s", _("bridge interfaces"));
         ret = -1;
         goto error;
     }
@@ -536,12 +537,18 @@ virInterfaceDefParseBondItfs(virInterfaceDefPtr def,
     int ret = 0;
 
     nbItf = virXPathNodeSet("./interface", ctxt, &interfaces);
-    if (nbItf <= 0) {
+    if (nbItf < 0) {
+        ret = -1;
+        goto error;
+    }
+
+    if (nbItf == 0) {
         virInterfaceReportError(VIR_ERR_XML_ERROR,
                                 "%s", _("bond has no interfaces"));
         ret = -1;
         goto error;
     }
+
     if (VIR_ALLOC_N(def->data.bond.itf, nbItf) < 0) {
         virReportOOMError();
         ret = -1;
index 4eb46faea1ff2cbee3d26d9762583975cc181bbd..e4765ea48c9459c74ae28cf4bd3187750d44bea0 100644 (file)
@@ -642,6 +642,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
     }
 
     nIps = virXPathNodeSet("./ip", ctxt, &ipNodes);
+    if (nIps < 0)
+        goto error;
+
     if (nIps > 0) {
         int ii;
 
index e9b8978b2cc772aac3d3e3466118a54ce8f3403b..dde292106a8a766ee23fe21757c9c4b1a5547ecc 100644 (file)
@@ -570,9 +570,6 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
     data->storage.serial     = virXPathString("string(./serial[1])", ctxt);
 
     if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) {
-        virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR,
-                                 _("error parsing storage capabilities for '%s'"),
-                                 def->name);
         goto out;
     }
 
@@ -735,9 +732,6 @@ virNodeDevCapScsiHostParseXML(xmlXPathContextPtr ctxt,
     }
 
     if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) {
-        virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR,
-                                 _("error parsing SCSI host capabilities for '%s'"),
-                                 def->name);
         goto out;
     }
 
@@ -1170,7 +1164,11 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, int create)
 
     /* Parse device capabilities */
     nodes = NULL;
-    if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) <= 0) {
+    if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) {
+        goto error;
+    }
+
+    if (n == 0) {
         virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR,
                                  _("no device capabilities for '%s'"),
                                  def->name);
index 9be4caea764dc9f9088d8f06d4eb28ab19859bd8..ed7d30065484ed3dabb4400cc1582755a84e8f1b 100644 (file)
@@ -438,6 +438,9 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
     source->initiator.iqn = virXPathString("string(./initiator/iqn/@name)", ctxt);
 
     nsource = virXPathNodeSet("./device", ctxt, &nodeset);
+    if (nsource < 0)
+        goto cleanup;
+
     if (nsource > 0) {
         if (VIR_ALLOC_N(source->devices, nsource) < 0) {
             VIR_FREE(nodeset);
index 9ec3dade3be1e847e5be0ca9ac667456a064c413..545efadf3d9158883574c9bb51e99e72ca80ea2b 100644 (file)
@@ -159,8 +159,6 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
 
     n = virXPathNodeSet("./secret", ctxt, &nodes);
     if (n < 0){
-        virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                              _("cannot extract volume encryption secrets"));
         goto cleanup;
     }
     if (n != 0 && VIR_ALLOC_N(ret->secrets, n) < 0) {
index 19e1938018354704148f18e8b7e1d1baee2edb14..f579439f4e2ed3e0c3f56bef3571331144ced005 100644 (file)
@@ -351,7 +351,6 @@ qemuDomainDefNamespaceParse(xmlDocPtr xml,
     /* first handle the extra command-line arguments */
     n = virXPathNodeSet("./qemu:commandline/qemu:arg", ctxt, &nodes);
     if (n < 0)
-        /* virXPathNodeSet already set the error */
         goto error;
 
     if (n && VIR_ALLOC_N(cmd->args, n) < 0)
@@ -372,7 +371,6 @@ qemuDomainDefNamespaceParse(xmlDocPtr xml,
     /* now handle the extra environment variables */
     n = virXPathNodeSet("./qemu:commandline/qemu:env", ctxt, &nodes);
     if (n < 0)
-        /* virXPathNodeSet already set the error */
         goto error;
 
     if (n && VIR_ALLOC_N(cmd->env_name, n) < 0)
index 0f0d77bc5eee5fdcdb60e9fe53205c772550aa44..8fdf916fc55bbf865a798916db082712e9c34db5 100644 (file)
@@ -681,8 +681,6 @@ static int testOpenVolumesForPool(xmlDocPtr xml,
     ret = virXPathNodeSet(vol_xpath, ctxt, &vols);
     VIR_FREE(vol_xpath);
     if (ret < 0) {
-        testError(VIR_ERR_XML_ERROR,
-                  _("node vol list for pool '%s'"), pool->def->name);
         goto error;
     }
 
@@ -892,7 +890,6 @@ static int testOpenFromFile(virConnectPtr conn,
 
     ret = virXPathNodeSet("/node/domain", ctxt, &domains);
     if (ret < 0) {
-        testError(VIR_ERR_XML_ERROR, "%s", _("node domain list"));
         goto error;
     }
 
@@ -936,7 +933,6 @@ static int testOpenFromFile(virConnectPtr conn,
 
     ret = virXPathNodeSet("/node/network", ctxt, &networks);
     if (ret < 0) {
-        testError(VIR_ERR_XML_ERROR, "%s", _("node network list"));
         goto error;
     }
     for (i = 0 ; i < ret ; i++) {
@@ -972,7 +968,6 @@ static int testOpenFromFile(virConnectPtr conn,
     /* Parse interface definitions */
     ret = virXPathNodeSet("/node/interface", ctxt, &ifaces);
     if (ret < 0) {
-        testError(VIR_ERR_XML_ERROR, "%s", _("node interface list"));
         goto error;
     }
     for (i = 0 ; i < ret ; i++) {
@@ -1008,7 +1003,6 @@ static int testOpenFromFile(virConnectPtr conn,
     /* Parse Storage Pool list */
     ret = virXPathNodeSet("/node/pool", ctxt, &pools);
     if (ret < 0) {
-        testError(VIR_ERR_XML_ERROR, "%s", _("node pool list"));
         goto error;
     }
     for (i = 0 ; i < ret ; i++) {
@@ -1059,7 +1053,6 @@ static int testOpenFromFile(virConnectPtr conn,
 
     ret = virXPathNodeSet("/node/device", ctxt, &devs);
     if (ret < 0) {
-        testError(VIR_ERR_XML_ERROR, "%s", _("node device list"));
         goto error;
     }
     for (i = 0 ; i < ret ; i++) {
index d2989e2a635274b9208dd64db5689ced9e69db19..05317eabc37b6cf09831c4f969fbc5e018c65e75 100644 (file)
@@ -601,10 +601,14 @@ virXPathNodeSet(const char *xpath,
     ctxt->node = relnode;
     if (obj == NULL)
         return(0);
+
     if (obj->type != XPATH_NODESET) {
+        virXMLError(VIR_ERR_INTERNAL_ERROR,
+                    _("Incorrect xpath '%s'"), xpath);
         xmlXPathFreeObject(obj);
         return (-1);
     }
+
     if ((obj->nodesetval == NULL)  || (obj->nodesetval->nodeNr < 0)) {
         xmlXPathFreeObject(obj);
         return (0);