diff options
author | Lorenz Kästle <lorenz.kaestle@netways.de> | 2023-03-09 11:03:48 +0100 |
---|---|---|
committer | Lorenz Kästle <lorenz.kaestle@netways.de> | 2023-03-09 11:03:48 +0100 |
commit | d0edb72a0c9bc1a28197ab4566928f7ee63a6d43 (patch) | |
tree | 6d524fb16d2dd1aa9f2d98529ef1de7a39f52700 /plugins/check_http.c | |
parent | 9fdc82f0543c6e2891c7079f70297f92e8ef4619 (diff) | |
parent | 269718094177fb8a7e3d3005d1310495009fe8c4 (diff) | |
download | monitoring-plugins-d0edb72a0c9bc1a28197ab4566928f7ee63a6d43.tar.gz |
Merge branch 'master' into RincewindsHat-patch-1
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index a9c22389..8dda046f 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); |
@@ -1439,29 +1438,37 @@ char *unchunk_content(const char *content) { | |||
1439 | overall_size += length_of_chunk; | 1438 | overall_size += length_of_chunk; |
1440 | 1439 | ||
1441 | if (result == NULL) { | 1440 | if (result == NULL) { |
1442 | result = (char *)calloc(length_of_chunk, sizeof(char)); | 1441 | // Size of the chunk plus the ending NULL byte |
1442 | result = (char *)malloc(length_of_chunk +1); | ||
1443 | if (result == NULL) { | 1443 | if (result == NULL) { |
1444 | if (verbose) { | 1444 | if (verbose) { |
1445 | printf("Failed to allocate memory for unchunked body\n"); | 1445 | printf("Failed to allocate memory for unchunked body\n"); |
1446 | } | 1446 | } |
1447 | return NULL; | 1447 | return NULL; |
1448 | } | 1448 | } |
1449 | result_ptr = result; | ||
1450 | } else { | 1449 | } else { |
1451 | void *tmp = realloc(result, overall_size); | 1450 | // Enlarge memory to the new size plus the ending NULL byte |
1451 | void *tmp = realloc(result, overall_size +1); | ||
1452 | if (tmp == NULL) { | 1452 | if (tmp == NULL) { |
1453 | if (verbose) { | 1453 | if (verbose) { |
1454 | printf("Failed to allocate memory for unchunked body\n"); | 1454 | printf("Failed to allocate memory for unchunked body\n"); |
1455 | } | 1455 | } |
1456 | return NULL; | 1456 | return NULL; |
1457 | } else { | ||
1458 | result = tmp; | ||
1457 | } | 1459 | } |
1458 | } | 1460 | } |
1459 | 1461 | ||
1460 | memcpy(result_ptr, start_of_chunk, size_of_chunk); | 1462 | memcpy(result + (overall_size - size_of_chunk), start_of_chunk, size_of_chunk); |
1461 | result_ptr = result_ptr + size_of_chunk; | ||
1462 | } | 1463 | } |
1463 | 1464 | ||
1464 | result[overall_size] = '\0'; | 1465 | if (overall_size == 0 && result == NULL) { |
1466 | // We might just have received the end chunk without previous content, so result is never allocated | ||
1467 | result = calloc(1, sizeof(char)); | ||
1468 | // No error handling here, we can only return NULL anyway | ||
1469 | } else { | ||
1470 | result[overall_size] = '\0'; | ||
1471 | } | ||
1465 | return result; | 1472 | return result; |
1466 | } | 1473 | } |
1467 | 1474 | ||