From: Lennart Poettering Date: Fri, 12 Oct 2018 13:59:21 +0000 (+0200) Subject: json: when creating an object, insist that every second item is a string X-Git-Tag: v240~473^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d77e781fd017946093bd71448e546cf59921ee22;p=thirdparty%2Fsystemd.git json: when creating an object, insist that every second item is a string After all, those are the keys, which have to be keys. --- diff --git a/src/basic/json.c b/src/basic/json.c index 8bf190ed586..72e8e115baf 100644 --- a/src/basic/json.c +++ b/src/basic/json.c @@ -589,6 +589,10 @@ int json_variant_new_object(JsonVariant **ret, JsonVariant **array, size_t n) { *c = array[v->n_elements]; uint16_t d; + if ((v->n_elements & 1) == 0 && + !json_variant_is_string(c)) + return -EINVAL; /* Every second one needs to be a string, as it is the key name */ + d = json_variant_depth(c); if (d >= DEPTH_MAX) /* Refuse too deep nesting */ return -ELNRNG;