[PATCH 2/3] virJSONValueObjectGetStringArray: Report error if @key is not an array

Michal Privoznik mprivozn at redhat.com
Tue Dec 1 11:50:15 UTC 2020


The virJSONValueObjectGetStringArray() function is given a @key
which is supposed to be an array inside given @object. Well, if
it's not then an error state is returned (NULL), but no error
message is set.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/util/virjson.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index d471923732..160f6172d2 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1472,8 +1472,12 @@ virJSONValueObjectGetStringArray(virJSONValuePtr object, const char *key)
     size_t i;
 
     data = virJSONValueObjectGetArray(object, key);
-    if (!data)
+    if (!data) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("%s is missing not an array"),
+                       key);
         return NULL;
+    }
 
     n = virJSONValueArraySize(data);
     ret = g_new0(char *, n + 1);
-- 
2.26.2




More information about the libvir-list mailing list