summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2020-08-22 13:18:10 +0200
committerTobias Stoeckmann <tobias@stoeckmann.org>2020-08-22 13:18:10 +0200
commitbcb6d7d3474b687718cbaee7bf203db4456fb6b3 (patch)
tree00afc5c0a972046276085e352c3a79586eb3089d
parent2b439ea59857747067e8272011ad67303e0d4cf1 (diff)
downloadjson-c-bcb6d7d3474b687718cbaee7bf203db4456fb6b3.tar.gz
Handle allocation failure in json_tokener_new_ex
The allocation of printbuf_new might fail. Return NULL to indicate tis error to the caller. Otherwise later usage of the returned tokener would lead to null pointer dereference.
-rw-r--r--json_tokener.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/json_tokener.c b/json_tokener.c
index 6527270..aad463a 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -134,6 +134,12 @@ struct json_tokener *json_tokener_new_ex(int depth)
return NULL;
}
tok->pb = printbuf_new();
+ if (!tok->pb)
+ {
+ free(tok);
+ free(tok->stack);
+ return NULL;
+ }
tok->max_depth = depth;
json_tokener_reset(tok);
return tok;