diff --git a/spa/tests/test-json.c b/spa/tests/test-json.c index 78c383871..dd510841f 100644 --- a/spa/tests/test-json.c +++ b/spa/tests/test-json.c @@ -71,7 +71,7 @@ static void expect_string(struct spa_json *it, const char *str) char *s; spa_assert((len = spa_json_next(it, &value)) > 0); check_type(TYPE_STRING, value, len); - s = alloca(len); + s = alloca(len+1); spa_json_parse_string(value, len, s); spa_assert(strcmp(s, str) == 0); } diff --git a/src/daemon/main.c b/src/daemon/main.c index 2b685d872..ef2a5fd17 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -168,7 +168,7 @@ static int parse_modules(struct data *d, const char *str) if (spa_json_is_container(aval, alen)) alen = spa_json_container_len(&it[2], aval, alen); - args = malloc(alen); + args = malloc(alen + 1); spa_json_parse_string(aval, alen, args); } else if (strcmp(arg, "flags") == 0) { flags = strndup(aval, alen); @@ -249,7 +249,8 @@ static int parse_objects(struct data *d, const char *str) if (strcmp(arg, "args") == 0) { if (spa_json_is_container(aval, alen)) alen = spa_json_container_len(&it[2], aval, alen); - args = malloc(alen); + + args = malloc(alen + 1); spa_json_parse_string(aval, alen, args); } else if (strcmp(arg, "flags") == 0) { flags = strndup(aval, alen); diff --git a/src/examples/media-session/match-rules.c b/src/examples/media-session/match-rules.c index c6a382ede..234542fe5 100644 --- a/src/examples/media-session/match-rules.c +++ b/src/examples/media-session/match-rules.c @@ -60,7 +60,7 @@ static bool find_match(struct spa_json *arr, struct pw_properties *props) if (spa_json_is_null(value, len)) { success = str == NULL; } else { - spa_json_parse_string(value, SPA_MIN(len, 1024), val); + spa_json_parse_string(value, SPA_MIN(len, 1023), val); value = val; len = strlen(val); } diff --git a/src/tools/pw-cli.c b/src/tools/pw-cli.c index cf8093c8b..b682bf34e 100644 --- a/src/tools/pw-cli.c +++ b/src/tools/pw-cli.c @@ -1616,7 +1616,7 @@ static int json_to_pod(struct spa_pod_builder *b, uint32_t id, spa_pod_builder_none(b); } else { - char *val = alloca(len); + char *val = alloca(len+1); spa_json_parse_string(value, len, val); switch (info->parent) { case SPA_TYPE_Id: