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

Ján Tomko jtomko at redhat.com
Tue Dec 1 15:42:03 UTC 2020


On a Tuesday in 2020, Michal Privoznik wrote:
>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"),

is missing or not an array

Unless I'm missing something.

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano

>+                       key);
>         return NULL;
>+    }
>
>     n = virJSONValueArraySize(data);
>     ret = g_new0(char *, n + 1);
>-- 
>2.26.2
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20201201/d4af0812/attachment-0001.sig>


More information about the libvir-list mailing list