Blame SOURCES/libvirt-qemuDomainGetGuestInfo-Don-t-try-to-free-a-negative-number-of-entries.patch

a41c76
From c03fef652341b4ee8969b2a0229e2ef9046a9cee Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <c03fef652341b4ee8969b2a0229e2ef9046a9cee@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 16 Mar 2020 22:11:35 +0100
a41c76
Subject: [PATCH] qemuDomainGetGuestInfo: Don't try to free a negative number
a41c76
 of entries
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
'nfs' variable was set to -1 or -2 on agent failure. Cleanup then tried
a41c76
to free 'nfs' elements of the array which resulted into a crash.
a41c76
a41c76
Make 'nfs' size_t and assign it only on successful agent call.
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1812965
a41c76
a41c76
Broken by commit 599ae372d8cf092
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 0fdb7385e416c9a0830dc60c0a56d55428963d74)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1812965
a41c76
Message-Id: <6eb97463bb380d32591ef82336095bf1ef370bca.1584391726.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_agent.c  |  2 +-
a41c76
 src/qemu/qemu_driver.c | 12 ++++++++----
a41c76
 2 files changed, 9 insertions(+), 5 deletions(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
a41c76
index ef2d2c500b..f13126aeee 100644
a41c76
--- a/src/qemu/qemu_agent.c
a41c76
+++ b/src/qemu/qemu_agent.c
a41c76
@@ -1954,7 +1954,7 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
-/* Returns: 0 on success
a41c76
+/* Returns: number of entries in '@info' on success
a41c76
  *          -2 when agent command is not supported by the agent
a41c76
  *          -1 otherwise
a41c76
  */
a41c76
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
a41c76
index 8c7e90531a..0bdb2851ec 100644
a41c76
--- a/src/qemu/qemu_driver.c
a41c76
+++ b/src/qemu/qemu_driver.c
a41c76
@@ -23101,7 +23101,7 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
a41c76
     g_autofree char *hostname = NULL;
a41c76
     unsigned int supportedTypes = types;
a41c76
     int rc;
a41c76
-    int nfs = 0;
a41c76
+    size_t nfs = 0;
a41c76
     qemuAgentFSInfoPtr *agentfsinfo = NULL;
a41c76
     size_t i;
a41c76
 
a41c76
@@ -23154,9 +23154,13 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
a41c76
         }
a41c76
     }
a41c76
     if (supportedTypes & VIR_DOMAIN_GUEST_INFO_FILESYSTEM) {
a41c76
-        rc = nfs = qemuAgentGetFSInfo(agent, &agentfsinfo);
a41c76
-        if (rc < 0 && !(rc == -2 && types == 0))
a41c76
-            goto exitagent;
a41c76
+        rc = qemuAgentGetFSInfo(agent, &agentfsinfo);
a41c76
+        if (rc < 0) {
a41c76
+            if (!(rc == -2 && types == 0))
a41c76
+                goto exitagent;
a41c76
+        } else {
a41c76
+            nfs = rc;
a41c76
+        }
a41c76
     }
a41c76
 
a41c76
     ret = 0;
a41c76
-- 
a41c76
2.25.1
a41c76