diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-02-10 18:31:54 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-02-11 11:53:07 +0100 |
commit | 14648b762f90b72a356e745cee3435531203704a (patch) | |
tree | e4dc25a590b0c394f43b41f2e4439165bde8552b /src/test/test-json.c | |
parent | ed2dc503da57b0110819563e0d1c85d023435e07 (diff) | |
download | systemd-14648b762f90b72a356e745cee3435531203704a.tar.gz |
test-json: do not pass ephemeral array as intializer to JSON_BUILD_STRV
Fixes #11600.
The code was effectively doing:
json_build(..., ({ char **_x = ((char**) ((const char*[]) {"one", "two", "three", "four", NULL })); _x; }));
but there was no guarantee that the storage for the array that _x points to
survives pass the end of the block. Essentially, STRV_MAKE cannot be used
inline inside of a block like this.
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r-- | src/test/test-json.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c index 9a9b01aa18..fdf1b4f40c 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -282,6 +282,7 @@ static void test_build(void) { a = json_variant_unref(a); b = json_variant_unref(b); + const char* arr_1234[] = {"one", "two", "three", "four", NULL}; assert_se(json_build(&a, JSON_BUILD_ARRAY(JSON_BUILD_OBJECT(JSON_BUILD_PAIR("x", JSON_BUILD_BOOLEAN(true)), JSON_BUILD_PAIR("y", JSON_BUILD_OBJECT(JSON_BUILD_PAIR("this", JSON_BUILD_NULL)))), JSON_BUILD_VARIANT(NULL), @@ -289,8 +290,9 @@ static void test_build(void) { JSON_BUILD_STRING(NULL), JSON_BUILD_NULL, JSON_BUILD_INTEGER(77), - JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")), JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))), - JSON_BUILD_STRV(STRV_MAKE("one", "two", "three", "four")))) >= 0); + JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")), + JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))), + JSON_BUILD_STRV((char**) arr_1234))) >= 0); assert_se(json_variant_format(a, 0, &s) >= 0); log_info("GOT: %s\n", s); |