json-c/bcb6d7d3474b687718cbaee7bf203db4456fb6b3.patch
2021-07-09 00:22:02 +02:00

30 lines
853 B
Diff

From bcb6d7d3474b687718cbaee7bf203db4456fb6b3 Mon Sep 17 00:00:00 2001
From: Tobias Stoeckmann <tobias@stoeckmann.org>
Date: Sat, 22 Aug 2020 13:18:10 +0200
Subject: [PATCH] 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.
---
json_tokener.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/json_tokener.c b/json_tokener.c
index 6527270dd4..aad463a0d2 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;