Skip to content
Open
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
17 changes: 17 additions & 0 deletions json_tokener.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ struct fjson_tokener *fjson_tokener_new_ex(int depth)
{
struct fjson_tokener *tok;

/* depth must be at least 1: fjson_tokener_reset() writes stack[0].
* A non-positive depth would calloc(0, ...) and then overflow. */
if (depth < 1)
return NULL;

tok = (struct fjson_tokener *)calloc(1, sizeof(struct fjson_tokener));
if (!tok)
return NULL;
Expand All @@ -116,6 +121,11 @@ struct fjson_tokener *fjson_tokener_new_ex(int depth)
return NULL;
}
tok->pb = printbuf_new();
if (!tok->pb) {
free(tok->stack);
free(tok);
return NULL;
}
tok->max_depth = depth;
fjson_tokener_reset(tok);
return tok;
Expand Down Expand Up @@ -857,6 +867,13 @@ struct fjson_object *fjson_tokener_parse_ex(struct fjson_tokener *tok, const cha
if (c == tok->quote_char) {
printbuf_memappend_fast(tok->pb, case_start, str - case_start);
obj_field_name = strdup(tok->pb->buf);
if (obj_field_name == NULL) {
/* out of memory: a NULL key would be
* interpreted as an empty slot, so we
* must not continue. */
tok->err = fjson_tokener_error_parse_eof;
goto out;
}
saved_state = fjson_tokener_state_object_field_end;
state = fjson_tokener_state_eatws;
break;
Expand Down