From ea2c85e0c153eef835d19fbd964059ceef45e536 Mon Sep 17 00:00:00 2001 From: simon987 Date: Tue, 18 Aug 2020 18:25:23 -0400 Subject: [PATCH] Fix heap buffer overflow warning --- src/index/elastic.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index/elastic.c b/src/index/elastic.c index 1fea575..4ecb199 100644 --- a/src/index/elastic.c +++ b/src/index/elastic.c @@ -436,7 +436,11 @@ char *elastic_get_status() { status[0] = '\0'; if (r->status_code == 200) { - json = cJSON_Parse(r->body); + char *tmp = malloc(r->size + 1); + memcpy(tmp, r->body, r->size); + *(tmp + r->size) = '\0'; + json = cJSON_Parse(tmp); + free(tmp); const cJSON *metadata = cJSON_GetObjectItem(json, "metadata"); if (metadata != NULL) { const cJSON *indices = cJSON_GetObjectItem(metadata, "indices");