mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-05 13:30:02 -05:00
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:
parent
7ee8df39e8
commit
0da9255057
3 changed files with 24 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue