Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ static struct json_result jp_parse_array(struct json_parser *p)
val.type = JSON_ARRAY;
val.v.array.count = count;
if (count > 0) {
if (count > SIZE_MAX / sizeof(struct json_value))
return jp_error(p, JSON_ERR_OVERFLOW);
val.v.array.items =
arena_alloc_array(p->arena, count, sizeof(struct json_value));
memcpy(val.v.array.items, tmp_items, count * sizeof(struct json_value));
Expand Down Expand Up @@ -349,6 +351,8 @@ static struct json_result jp_parse_object(struct json_parser *p)
val.type = JSON_OBJECT;
val.v.object.count = count;
if (count > 0) {
if (count > SIZE_MAX / sizeof(struct json_kv))
return jp_error(p, JSON_ERR_OVERFLOW);
val.v.object.pairs =
arena_alloc_array(p->arena, count, sizeof(struct json_kv));
memcpy(val.v.object.pairs, tmp_pairs, count * sizeof(struct json_kv));
Expand Down
Loading