From d77e781fd017946093bd71448e546cf59921ee22 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 15:59:21 +0200 Subject: [PATCH] json: when creating an object, insist that every second item is a string After all, those are the keys, which have to be keys. --- src/basic/json.c | 4 ++++ 1 file changed, 4 insertions(+) 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; -- 2.47.3