3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 02:09:38 +01:00

json: restrict json_iter_{parse,next} to objects/arrays

json_iter_parse is only meant to work on objects while
json_iter_next is only meant to work on arrays.

This adds checks in both APIs to ensure they aren't being
used incorrectly.
This commit is contained in:
James Prestwood 2022-01-06 14:52:57 -08:00 committed by Denis Kenzior
parent 1f91c03bf6
commit 67ded4c2fd

View File

@ -200,6 +200,9 @@ bool json_iter_parse(struct json_iter *iter, enum json_type type, ...)
if (iter->start == -1) if (iter->start == -1)
return false; return false;
if (c->tokens[iter->start].type != JSMN_OBJECT)
return false;
args = l_queue_new(); args = l_queue_new();
va_start(va, type); va_start(va, type);
@ -427,6 +430,9 @@ bool json_iter_next(struct json_iter *iter)
jsmntok_t *t = c->tokens + iter->current; jsmntok_t *t = c->tokens + iter->current;
int inc = 1; int inc = 1;
if (c->tokens[iter->start].type != JSMN_ARRAY)
return false;
/* /*
* If this is the initial iteration skip this and just increment * If this is the initial iteration skip this and just increment
* current by 1 since this iterator points to a container which needs to * current by 1 since this iterator points to a container which needs to