]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuAgentGetDisks: Don't use virJSONValueObjectGetStringArray for optional data
authorPeter Krempa <pkrempa@redhat.com>
Thu, 1 Dec 2022 16:02:42 +0000 (17:02 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Dec 2022 15:18:37 +0000 (16:18 +0100)
The 'dependencies' field in the return data may be missing in some
cases. Historically 'virJSONValueObjectGetStringArray' didn't report
error in such case, but later refactor (commit 043b50b948ef3c2 ) added
an error in order to use it in other places too.

Unfortunately this results in the error log being spammed with an
irrelevant error in case when qemuAgentGetDisks is invoked on a VM
running windows.

Replace the use of virJSONValueObjectGetStringArray by fetching the
array first and calling virJSONValueArrayToStringList only when we have
an array.

Fixes: 043b50b948ef3c2a4adf5fa32a93ec2589851ac6
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2149752
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_agent.c

index d420b2b901ff65800c9cd1629d3fcc2915d98b40..70d45955b27514c5cdb65d2301927459405b77f9 100644 (file)
@@ -2545,6 +2545,7 @@ int qemuAgentGetDisks(qemuAgent *agent,
     for (i = 0; i < ndata; i++) {
         virJSONValue *addr;
         virJSONValue *entry = virJSONValueArrayGet(data, i);
+        virJSONValue *dependencies;
         qemuAgentDiskInfo *disk;
 
         if (!entry) {
@@ -2570,7 +2571,11 @@ int qemuAgentGetDisks(qemuAgent *agent,
             goto error;
         }
 
-        disk->dependencies = virJSONValueObjectGetStringArray(entry, "dependencies");
+        if ((dependencies = virJSONValueObjectGetArray(entry, "dependencies"))) {
+            if (!(disk->dependencies = virJSONValueArrayToStringList(dependencies)))
+                goto error;
+        }
+
         disk->alias = g_strdup(virJSONValueObjectGetString(entry, "alias"));
         addr = virJSONValueObjectGetObject(entry, "address");
         if (addr) {