json: spa_json_get_string() writes up to len chars or fail

This commit is contained in:
Wim Taymans 2022-01-04 10:42:32 +01:00
parent 68b31d37d9
commit c46113faa3
17 changed files with 26 additions and 26 deletions

View file

@ -1010,7 +1010,7 @@ static int json_object_find(const char *obj, const char *key, char *value, size_
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
return -EINVAL;
while (spa_json_get_string(&it[1], k, sizeof(k)-1) > 0) {
while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) {
if (spa_streq(k, key)) {
if (spa_json_get_string(&it[1], value, len) <= 0)
continue;

View file

@ -46,7 +46,7 @@ static bool find_match(struct spa_json *arr, const struct spa_dict *props)
int match = 0, fail = 0;
int len;
while (spa_json_get_string(&it[0], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
bool success = false;
if ((len = spa_json_next(&it[0], &value)) <= 0)
@ -103,7 +103,7 @@ int pw_jack_match_rules(const char *rules, size_t size, const struct spa_dict *p
char key[64];
bool have_match = false, have_actions = false;
while (spa_json_get_string(&it[2], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
if (spa_streq(key, "matches")) {
if (spa_json_enter_array(&it[2], &it[3]) < 0)
break;
@ -120,7 +120,7 @@ int pw_jack_match_rules(const char *rules, size_t size, const struct spa_dict *p
if (!have_match || !have_actions)
continue;
while (spa_json_get_string(&actions, key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&actions, key, sizeof(key)) > 0) {
int res, len;
pw_log_debug("action %s", key);

View file

@ -2489,7 +2489,7 @@ static int json_object_find(const char *obj, const char *key, char *value, size_
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
return -EINVAL;
while (spa_json_get_string(&it[1], k, sizeof(k)-1) > 0) {
while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) {
if (spa_streq(k, key)) {
if (spa_json_get_string(&it[1], value, len) <= 0)
continue;

View file

@ -110,7 +110,7 @@ static int do_match(const char *rules, struct spa_dict *dict, uint32_t *no_featu
int match = true;
uint32_t no_features_cur = 0;
while (spa_json_get_string(&it[0], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
char val[4096];
const char *str, *value;
int len;
@ -118,7 +118,7 @@ static int do_match(const char *rules, struct spa_dict *dict, uint32_t *no_featu
if (spa_streq(key, "no-features")) {
if (spa_json_enter_array(&it[0], &it[1]) > 0) {
while (spa_json_get_string(&it[1], val, sizeof(val)-1) > 0)
while (spa_json_get_string(&it[1], val, sizeof(val)) > 0)
no_features_cur |= parse_feature(val);
}
continue;
@ -183,7 +183,7 @@ static void load_quirks(struct spa_bt_quirks *this, const char *str, size_t len)
if (spa_json_enter_object(&data, &rules) <= 0)
spa_json_init(&rules, str, len);
while (spa_json_get_string(&rules, key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&rules, key, sizeof(key)) > 0) {
int sz;
const char *value;

View file

@ -69,7 +69,7 @@ support_log_parse_patterns(struct spa_list *patterns, const char *jsonstr)
while (spa_json_enter_object(&array, &elem) > 0) {
char pattern[512] = {0};
while (spa_json_get_string(&elem, pattern, sizeof(pattern) - 1) > 0) {
while (spa_json_get_string(&elem, pattern, sizeof(pattern)) > 0) {
struct support_log_pattern *p;
const char *val;
int len;

View file

@ -90,7 +90,7 @@ static int dump(FILE *file, int indent, struct spa_json *it, const char *value,
} else if (spa_json_is_object(value, len)) {
fprintf(file, "{");
spa_json_enter(it, &sub);
while (spa_json_get_string(&sub, key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&sub, key, sizeof(key)) > 0) {
fprintf(file, "%s\n%*s",
count++ > 0 ? "," : "",
indent+2, "");

View file

@ -165,7 +165,7 @@ static int do_extension_stream_restore_read(struct client *client, uint32_t comm
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
continue;
while (spa_json_get_string(&it[1], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
if (spa_streq(key, "volume")) {
if (spa_json_get_float(&it[1], &volume) <= 0)
continue;

View file

@ -42,7 +42,7 @@ static int bluez_card_object_message_handler(struct pw_manager *m, struct pw_man
return -EINVAL;
spa_json_init(&it, params, strlen(params));
if (spa_json_get_string(&it, codec, sizeof(codec)-1) <= 0)
if (spa_json_get_string(&it, codec, sizeof(codec)) <= 0)
return -EINVAL;
codec_id = atoi(codec);

View file

@ -771,7 +771,7 @@ static int json_object_find(const char *obj, const char *key, char *value, size_
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
return -EINVAL;
while (spa_json_get_string(&it[1], k, sizeof(k)-1) > 0) {
while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) {
if (spa_streq(k, key)) {
if (spa_json_get_string(&it[1], value, len) <= 0)
continue;

View file

@ -75,7 +75,7 @@ static int match(const char *rules, struct spa_dict *dict, uint64_t *quirks)
int match = true;
uint64_t quirks_cur = 0;
while (spa_json_get_string(&it[0], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
char val[4096];
const char *str, *value;
int len;
@ -83,7 +83,7 @@ static int match(const char *rules, struct spa_dict *dict, uint64_t *quirks)
if (spa_streq(key, "quirks")) {
if (spa_json_enter_array(&it[0], &it[1]) > 0) {
while (spa_json_get_string(&it[1], val, sizeof(val)-1) > 0)
while (spa_json_get_string(&it[1], val, sizeof(val)) > 0)
quirks_cur |= parse_quirks(val);
}
continue;

View file

@ -942,7 +942,7 @@ int servers_create_and_start(struct impl *impl, const char *addresses, struct pw
if (spa_json_enter_array(&it[0], &it[1]) < 0)
return -EINVAL;
while (spa_json_get_string(&it[1], addr_str, sizeof(addr_str) - 1) > 0) {
while (spa_json_get_string(&it[1], addr_str, sizeof(addr_str)) > 0) {
res = parse_address(addr_str, &addrs);
if (res < 0) {
pw_log_warn("pulse-server %p: failed to parse address '%s': %s",

View file

@ -787,7 +787,7 @@ static int parse_params(struct impl *impl)
spa_json_init(&it[0], str, strlen(str));
if (spa_json_enter_array(&it[0], &it[1]) > 0) {
while (spa_json_get_string(&it[1], value, sizeof(value)-1) > 0) {
while (spa_json_get_string(&it[1], value, sizeof(value)) > 0) {
if (create_server(impl, value) == NULL) {
pw_log_warn("%p: can't create server for %s: %m",
impl, value);

View file

@ -393,8 +393,8 @@ static int parse_spa_libs(struct pw_context *context, char *str)
return -EINVAL;
}
while (spa_json_get_string(&it[1], key, sizeof(key)-1) > 0) {
if (spa_json_get_string(&it[1], value, sizeof(value)-1) > 0) {
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
if (spa_json_get_string(&it[1], value, sizeof(value)) > 0) {
pw_context_add_spa_lib(context, key, value);
count++;
}
@ -445,7 +445,7 @@ static int parse_modules(struct pw_context *context, char *str)
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
char *name = NULL, *args = NULL, *flags = NULL;
while (spa_json_get_string(&it[2], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
const char *val;
int len;
@ -529,7 +529,7 @@ static int parse_objects(struct pw_context *context, char *str)
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
char *factory = NULL, *args = NULL, *flags = NULL;
while (spa_json_get_string(&it[2], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
const char *val;
int len;
@ -616,7 +616,7 @@ static int parse_exec(struct pw_context *context, char *str)
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
char *path = NULL, *args = NULL;
while (spa_json_get_string(&it[2], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
const char *val;
int len;

View file

@ -166,7 +166,7 @@ int pw_properties_update_string(struct pw_properties *props, const char *str, si
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
spa_json_init(&it[1], str, size);
while (spa_json_get_string(&it[1], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
int len;
const char *value;

View file

@ -112,7 +112,7 @@ static uint32_t parse_uint32_array(const char *str, uint32_t *vals, uint32_t max
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
spa_json_init(&it[1], str, strlen(str));
while (spa_json_get_string(&it[1], v, sizeof(v)-1) > 0 &&
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
count < max) {
if (spa_atou32(v, &r, 0))
vals[count++] = r;

View file

@ -694,7 +694,7 @@ static int json_object_find(const char *obj, const char *key, char *value, size_
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
return -EINVAL;
while (spa_json_get_string(&it[1], k, sizeof(k)-1) > 0) {
while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) {
if (spa_streq(k, key)) {
if (spa_json_get_string(&it[1], value, len) <= 0)
continue;

View file

@ -1562,7 +1562,7 @@ static int json_to_pod(struct spa_pod_builder *b, uint32_t id,
spa_pod_builder_push_object(b, &f[0], info->parent, id);
spa_json_enter(iter, &it[0]);
while (spa_json_get_string(&it[0], key, sizeof(key)-1) > 0) {
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
const struct spa_type_info *pi;
if ((l = spa_json_next(&it[0], &v)) <= 0)
break;