From: Tobias Stoeckmann Date: Sat, 22 Aug 2020 11:18:10 +0000 (+0200) Subject: Handle allocation failure in json_tokener_new_ex X-Git-Tag: json-c-0.16-20220414~37^2~16^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F665%2Fhead;p=thirdparty%2Fjson-c.git 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. --- diff --git a/json_tokener.c b/json_tokener.c index 6527270d..aad463a0 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;