From 3af707bc072806a1c4919938101f45e71d77a300 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 11 Jun 2019 15:07:29 +0000 Subject: [PATCH] fixed a buffer management bug in json.c --- lib/json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/json.c b/lib/json.c index 5fdf64d..9e516fe 100644 --- a/lib/json.c +++ b/lib/json.c @@ -165,11 +165,11 @@ static int add_char_to_token (hcl_json_t* json, hcl_ooch_t ch) hcl_ooch_t* tmp; hcl_oow_t newcapa; - newcapa = HCL_ALIGN_POW2(json->tok.len + 1, HCL_JSON_TOKEN_NAME_ALIGN); + newcapa = HCL_ALIGN_POW2(json->tok.len + 2, HCL_JSON_TOKEN_NAME_ALIGN); /* +2 here because of -1 when setting newcapa */ tmp = (hcl_ooch_t*)hcl_json_reallocmem(json, json->tok.ptr, newcapa * HCL_SIZEOF(*tmp)); if (!tmp) return -1; - json->tok_capa = newcapa; + json->tok_capa = newcapa - 1; /* -1 to secure space for terminating null */ json->tok.ptr = tmp; }