json: when creating an object, insist that every second item is a string

After all, those are the keys, which have to be keys.
This commit is contained in:
Lennart Poettering 2018-10-12 15:59:21 +02:00
parent b2fa0d4fca
commit d77e781fd0
1 changed files with 4 additions and 0 deletions

View File

@ -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;