render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
dc2b6e
From 1ad707f19e570b76c1f6517194d9cc86b084014d Mon Sep 17 00:00:00 2001
dc2b6e
Message-Id: <1ad707f19e570b76c1f6517194d9cc86b084014d@dist-git>
dc2b6e
From: Peter Krempa <pkrempa@redhat.com>
dc2b6e
Date: Thu, 1 Dec 2022 17:02:42 +0100
dc2b6e
Subject: [PATCH] qemuAgentGetDisks: Don't use virJSONValueObjectGetStringArray
dc2b6e
 for optional data
dc2b6e
dc2b6e
The 'dependencies' field in the return data may be missing in some
dc2b6e
cases. Historically 'virJSONValueObjectGetStringArray' didn't report
dc2b6e
error in such case, but later refactor (commit 043b50b948ef3c2 ) added
dc2b6e
an error in order to use it in other places too.
dc2b6e
dc2b6e
Unfortunately this results in the error log being spammed with an
dc2b6e
irrelevant error in case when qemuAgentGetDisks is invoked on a VM
dc2b6e
running windows.
dc2b6e
dc2b6e
Replace the use of virJSONValueObjectGetStringArray by fetching the
dc2b6e
array first and calling virJSONValueArrayToStringList only when we have
dc2b6e
an array.
dc2b6e
dc2b6e
Fixes: 043b50b948ef3c2a4adf5fa32a93ec2589851ac6
dc2b6e
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2149752
dc2b6e
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
dc2b6e
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
dc2b6e
(cherry picked from commit 3b576601dfb924bb518870a01de5d1a421cbb467)
dc2b6e
---
dc2b6e
 src/qemu/qemu_agent.c | 7 ++++++-
dc2b6e
 1 file changed, 6 insertions(+), 1 deletion(-)
dc2b6e
dc2b6e
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
dc2b6e
index f33cd47078..8a55044c9e 100644
dc2b6e
--- a/src/qemu/qemu_agent.c
dc2b6e
+++ b/src/qemu/qemu_agent.c
dc2b6e
@@ -2550,6 +2550,7 @@ int qemuAgentGetDisks(qemuAgent *agent,
dc2b6e
     for (i = 0; i < ndata; i++) {
dc2b6e
         virJSONValue *addr;
dc2b6e
         virJSONValue *entry = virJSONValueArrayGet(data, i);
dc2b6e
+        virJSONValue *dependencies;
dc2b6e
         qemuAgentDiskInfo *disk;
dc2b6e
 
dc2b6e
         if (!entry) {
dc2b6e
@@ -2575,7 +2576,11 @@ int qemuAgentGetDisks(qemuAgent *agent,
dc2b6e
             goto error;
dc2b6e
         }
dc2b6e
 
dc2b6e
-        disk->dependencies = virJSONValueObjectGetStringArray(entry, "dependencies");
dc2b6e
+        if ((dependencies = virJSONValueObjectGetArray(entry, "dependencies"))) {
dc2b6e
+            if (!(disk->dependencies = virJSONValueArrayToStringList(dependencies)))
dc2b6e
+                goto error;
dc2b6e
+        }
dc2b6e
+
dc2b6e
         disk->alias = g_strdup(virJSONValueObjectGetString(entry, "alias"));
dc2b6e
         addr = virJSONValueObjectGetObject(entry, "address");
dc2b6e
         if (addr) {
dc2b6e
-- 
dc2b6e
2.39.0
dc2b6e