]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
json: when creating an object, insist that every second item is a string
authorLennart Poettering <lennart@poettering.net>
Fri, 12 Oct 2018 13:59:21 +0000 (15:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 14:44:51 +0000 (16:44 +0200)
After all, those are the keys, which have to be keys.

src/basic/json.c

index 8bf190ed586d1d24a5eba78d3bf6f5e98cc713e2..72e8e115baf4d7b1a7be099ee0e8a980fec6875d 100644 (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;