diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index a9c2238..5fa310f 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,26 +1438,28 @@ 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 | result[overall_size] = '\0'; |