json: handle overflow better

We need at least the length of the string+1 as the length of the
target in spa_json_get_string(). Add a unit test for this.
This commit is contained in:
Wim Taymans 2021-03-18 19:44:25 +01:00
parent fc9a6d6b1e
commit db85339f50
2 changed files with 18 additions and 1 deletions

View file

@ -351,7 +351,7 @@ static inline int spa_json_get_string(struct spa_json *iter, char *res, int maxl
{
const char *value;
int len;
if ((len = spa_json_next(iter, &value)) <= 0 || maxlen < len)
if ((len = spa_json_next(iter, &value)) <= 0 || maxlen <= len)
return -1;
return spa_json_parse_string(value, len, res);
}