mirror of
https://github.com/json-c/json-c.git
synced 2026-04-09 07:19:06 +08:00
Fix use-after-free in json_tokener_new_ex()
The failure path taken in the event of printbuf_new() returning NULL
calls free() on tok->stack after already having freed tok. Swap the
order of the two calls to fix an obvious memory access violation.
Fixes: bcb6d7d347 ("Handle allocation failure in json_tokener_new_ex")
Signed-off-by: Juuso Alasuutari <juuso.alasuutari@gmail.com>
This commit is contained in:
@@ -164,8 +164,8 @@ struct json_tokener *json_tokener_new_ex(int depth)
|
|||||||
tok->pb = printbuf_new();
|
tok->pb = printbuf_new();
|
||||||
if (!tok->pb)
|
if (!tok->pb)
|
||||||
{
|
{
|
||||||
free(tok);
|
|
||||||
free(tok->stack);
|
free(tok->stack);
|
||||||
|
free(tok);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
tok->max_depth = depth;
|
tok->max_depth = depth;
|
||||||
|
|||||||
Reference in New Issue
Block a user