From d3fbcd122012af7733de3b80a692f79ad69057b2 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 30 Jan 2023 13:33:46 +0100 Subject: check_http: Add space for ending NULL byte in array for chunked encoding --- plugins/check_http.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/check_http.c b/plugins/check_http.c index c23625e9..5fa310f5 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1438,7 +1438,8 @@ char *unchunk_content(const char *content) { overall_size += length_of_chunk; if (result == NULL) { - result = (char *)calloc(length_of_chunk, sizeof(char)); + // Size of the chunk plus the ending NULL byte + result = (char *)malloc(length_of_chunk +1); if (result == NULL) { if (verbose) { printf("Failed to allocate memory for unchunked body\n"); @@ -1446,7 +1447,8 @@ char *unchunk_content(const char *content) { return NULL; } } else { - void *tmp = realloc(result, overall_size); + // Enlarge memory to the new size plus the ending NULL byte + void *tmp = realloc(result, overall_size +1); if (tmp == NULL) { if (verbose) { printf("Failed to allocate memory for unchunked body\n"); -- cgit v1.2.3-74-g34f1