render / rpms / libvirt

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