virJSONValueObjectGetStringArray: Report error if @key is not an array

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2020-12-01 12:10:34 +01:00
parent ebc241fcff
commit 043b50b948

View File

@ -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 or not an array"),
key);
return NULL;
}
n = virJSONValueArraySize(data);
ret = g_new0(char *, n + 1);