mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-26 02:19:26 +01:00
json: Tighten up json_iter_get_int/get_uint
- Ensure that input isn't an empty string - Ensure that EINVAL errno (which could be optionally returned by strto{ul|l} is also checked. - Since strtoul allows '+' and '-' characters in input, ensure that input which is expected to be an unsigned number doesn't start with '-'
This commit is contained in:
parent
26b7446178
commit
30b04bc3bb
10
src/json.c
10
src/json.c
@ -309,13 +309,16 @@ bool json_iter_get_int(struct json_iter *iter, int *i)
|
|||||||
if (!iter_get_primitive_data(iter, &ptr, &len))
|
if (!iter_get_primitive_data(iter, &ptr, &len))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!len)
|
||||||
|
return false;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
t = r = strtol(ptr, &endp, 10);
|
t = r = strtol(ptr, &endp, 10);
|
||||||
if (endp != ptr + len)
|
if (endp != ptr + len)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (errno == ERANGE || r != t)
|
if (errno == ERANGE || errno == EINVAL || r != t)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
@ -335,13 +338,16 @@ bool json_iter_get_uint(struct json_iter *iter, unsigned int *i)
|
|||||||
if (!iter_get_primitive_data(iter, &ptr, &len))
|
if (!iter_get_primitive_data(iter, &ptr, &len))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!len || *((char *) ptr) == '-')
|
||||||
|
return false;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
t = r = strtoul(ptr, &endp, 10);
|
t = r = strtoul(ptr, &endp, 10);
|
||||||
if (endp != ptr + len)
|
if (endp != ptr + len)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (errno == ERANGE || r != t)
|
if (errno == ERANGE || errno == EINVAL || r != t)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
|
Loading…
Reference in New Issue
Block a user