Skip to content

Commit f5011e1

Browse files
committed
fix DOM path realloc overflow
1 parent 7c9c5ff commit f5011e1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/json/centijson_dom.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,14 @@ json_dom_process(JSON_TYPE type, const unsigned char* data, size_t data_size, vo
266266
* append their json_values. */
267267
if(dom_parser->path_size >= dom_parser->path_alloc) {
268268
JSON_VALUE** new_path;
269-
size_t new_path_alloc = dom_parser->path_alloc * 2;
269+
size_t new_path_alloc;
270270

271-
if(new_path_alloc == 0)
271+
if(dom_parser->path_alloc == 0)
272272
new_path_alloc = 32;
273+
else if(dom_parser->path_alloc > SIZE_MAX / 2 / sizeof(JSON_VALUE*))
274+
return JSON_ERR_OUTOFMEMORY;
275+
else
276+
new_path_alloc = dom_parser->path_alloc * 2;
273277
new_path = (JSON_VALUE**) realloc((void *)dom_parser->path, new_path_alloc * sizeof(JSON_VALUE*));
274278
if(new_path == NULL)
275279
return JSON_ERR_OUTOFMEMORY;

0 commit comments

Comments
 (0)