diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2023-01-30 12:45:20 +0100 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2023-01-30 12:45:20 +0100 |
commit | d9528c265b96a5a0f0c2e43ac74ab3921a2987e1 (patch) | |
tree | 265c6142f93d09e1992e80d0b2784650079517f7 /plugins/check_http.c | |
parent | 67b472f9d1d29b9de5312c46f13ca4f5a656c4da (diff) | |
download | monitoring-plugins-d9528c265b96a5a0f0c2e43ac74ab3921a2987e1.tar.gz |
check_http: Fix memory reallocation error in chunk decoding logic
This patch should fix an error with the way memory reallocation was
used, which resulted in "realloc(): invalid next size".
It is not completely clear to me as to what caused this problem, but
apparently one can not depend handing a pointer to "realloc(3)" and
expect that it still works afterwards, but one should/must use the one
returned by the function.
Also this patch replaces a variable which was used to remember the
position in the array by just computing that from the current values.
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index a9c22389..c23625e9 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -1399,7 +1399,6 @@ char *unchunk_content(const char *content) { | |||
1399 | char *endptr; | 1399 | char *endptr; |
1400 | long length_of_chunk = 0; | 1400 | long length_of_chunk = 0; |
1401 | size_t overall_size = 0; | 1401 | size_t overall_size = 0; |
1402 | char *result_ptr; | ||
1403 | 1402 | ||
1404 | while (true) { | 1403 | while (true) { |
1405 | size_of_chunk = strtol(pointer, &endptr, 16); | 1404 | size_of_chunk = strtol(pointer, &endptr, 16); |
@@ -1446,7 +1445,6 @@ char *unchunk_content(const char *content) { | |||
1446 | } | 1445 | } |
1447 | return NULL; | 1446 | return NULL; |
1448 | } | 1447 | } |
1449 | result_ptr = result; | ||
1450 | } else { | 1448 | } else { |
1451 | void *tmp = realloc(result, overall_size); | 1449 | void *tmp = realloc(result, overall_size); |
1452 | if (tmp == NULL) { | 1450 | if (tmp == NULL) { |
@@ -1454,11 +1452,12 @@ char *unchunk_content(const char *content) { | |||
1454 | printf("Failed to allocate memory for unchunked body\n"); | 1452 | printf("Failed to allocate memory for unchunked body\n"); |
1455 | } | 1453 | } |
1456 | return NULL; | 1454 | return NULL; |
1455 | } else { | ||
1456 | result = tmp; | ||
1457 | } | 1457 | } |
1458 | } | 1458 | } |
1459 | 1459 | ||
1460 | memcpy(result_ptr, start_of_chunk, size_of_chunk); | 1460 | memcpy(result + (overall_size - size_of_chunk), start_of_chunk, size_of_chunk); |
1461 | result_ptr = result_ptr + size_of_chunk; | ||
1462 | } | 1461 | } |
1463 | 1462 | ||
1464 | result[overall_size] = '\0'; | 1463 | result[overall_size] = '\0'; |