treewide: check for JSON parse errors

Check for JSON parse errors, and log error messages as appropriate.

It's mostly enough to do this where the input is parsed for the first
time, e.g. via pw_properties_new_string, as that already validates the
JSON syntax.
This commit is contained in:
Pauli Virtanen 2024-03-23 16:25:45 +02:00
parent 7ee8df39e8
commit 0da9255057
3 changed files with 24 additions and 2 deletions

View file

@ -1277,6 +1277,7 @@ static int get_data_from_json(struct data *data, const char *json_path)
struct stat sbuf;
struct spa_json it[2];
const char *value;
int line, col;
if ((fd = open(json_path, O_CLOEXEC | O_RDONLY)) < 0) {
fprintf(stderr, "error opening file '%s': %m\n", json_path);
@ -1312,6 +1313,12 @@ static int get_data_from_json(struct data *data, const char *json_path)
}
munmap(json, sbuf.st_size);
if (spa_json_get_error(&it[0], json, &line, &col)) {
fprintf(stderr, "JSON syntax error on line:%d col:%d\n", line, col);
return -1;
}
return 0;
}