json: avoid converting random string to floats

Only allow the json float characters when converting to float.
This avoids NAN, INF, 0xffe4 etc to be seen as a json float.
This commit is contained in:
Wim Taymans 2022-07-11 11:50:58 +02:00
parent bdfde2fdf0
commit cbbc4baa3f
2 changed files with 3 additions and 1 deletions

View file

@ -240,6 +240,8 @@ static inline bool spa_json_is_null(const char *val, int len)
static inline int spa_json_parse_float(const char *val, int len, float *result)
{
char *end;
if (strspn(val, "+-0123456789.Ee") < (size_t)len)
return 0;
*result = spa_strtof(val, &end);
return len > 0 && end == val + len;
}