json: improve unicode parsing

Make sure don't overread the strings.
Don't use sscanf but use a custom hex read function.

Fixes #2340
This commit is contained in:
Wim Taymans 2022-04-27 08:37:32 +02:00
parent f641e4ecb3
commit 92e2b7dd0d
2 changed files with 31 additions and 9 deletions

View file

@ -179,6 +179,9 @@ PWTEST(json_encode)
strcpy(dst, "\"\\u03b2a\"");
pwtest_int_eq(spa_json_parse_stringn(dst, sizeof(dst), result, sizeof(result)), 1);
pwtest_str_eq(result, "\316\262a");
strcpy(dst, "\"\\u 03b2a \"");
pwtest_int_eq(spa_json_parse_stringn(dst, sizeof(dst), result, sizeof(result)), 1);
pwtest_str_eq(result, "u 03b2a ");
return PWTEST_PASS;
}