]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Handle allocation failure in json_tokener_new_ex 665/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 22 Aug 2020 11:18:10 +0000 (13:18 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 22 Aug 2020 11:18:10 +0000 (13:18 +0200)
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.

json_tokener.c

index 6527270dd475e058a99f029d52789cec501206ba..aad463a0d22c49bc606c17368846bc4d954cf343 100644 (file)
@@ -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;