]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMigrationCookieXMLParse: Check domain element count more defensively
authorPeter Krempa <pkrempa@redhat.com>
Wed, 30 Sep 2020 13:00:43 +0000 (15:00 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Oct 2020 13:58:52 +0000 (15:58 +0200)
Make sure that 'virXPathNodeSet' returns '1' as the only expected value
rather than relying on the fact that the previous check for the number
of elements ensures success of the subsequent call.

The error message no longer mentions the number of <domain> elements in
the cookie, but this is a very unlikely internal error anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_migration_cookie.c

index 5bd1746543d55febd17ea9b01d77ea96edc61b61..6f7d94bd2c3ff8d000ed4489d7b7f6e661cc7d54 100644 (file)
@@ -1212,7 +1212,6 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
     g_autofree char *hostuuid = NULL;
     char localdomuuid[VIR_UUID_STRING_BUFLEN];
     xmlNodePtr *nodes = NULL;
-    int n;
 
     /* We don't store the uuid, name, hostname, or hostuuid
      * values. We just compare them to local data to do some
@@ -1297,11 +1296,9 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
 
     if ((flags & QEMU_MIGRATION_COOKIE_PERSISTENT) &&
         virXPathBoolean("count(./domain) > 0", ctxt)) {
-        if ((n = virXPathNodeSet("./domain", ctxt, &nodes)) > 1) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Too many domain elements in "
-                             "migration cookie: %d"),
-                           n);
+        if ((virXPathNodeSet("./domain", ctxt, &nodes)) != 1) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Too many domain elements in migration cookie"));
             goto error;
         }
         mig->persistent = virDomainDefParseNode(doc, nodes[0],