summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2022-11-13 23:35:19 (GMT)
committerSven Nierlein <sven@nierlein.org>2023-01-07 17:34:46 (GMT)
commit029168276fc3a02daa676c4fcc7a597e3319929a (patch)
tree35a360da068ece4710699b1f7c3898ac2dfa4fe5
parent3e63e61f6ae062fd1e8c8c962c0bb603cf88856c (diff)
downloadmonitoring-plugins-0291682.tar.gz
Fix several bug in the implementation of unchunking
-rw-r--r--plugins/check_http.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 1f7bd0b..d5b6b37 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1267,11 +1267,15 @@ int check_http(void) {
1267 regmatch_t chre_pmatch[1]; // We actually do not care about this, since we only want to know IF it was found 1267 regmatch_t chre_pmatch[1]; // We actually do not care about this, since we only want to know IF it was found
1268 1268
1269 if (regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) { 1269 if (regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) {
1270 if (verbose) {
1271 printf("Found chunked content\n");
1272 }
1270 // We actually found the chunked header 1273 // We actually found the chunked header
1271 char *tmp = unchunk_content(page); 1274 char *tmp = unchunk_content(page);
1272 if (tmp == NULL) { 1275 if (tmp == NULL) {
1273 die(STATE_UNKNOWN, "HTTP %s: %s\n", state_text(STATE_UNKNOWN), "Failed to unchunk message body"); 1276 die(STATE_UNKNOWN, "HTTP %s: %s\n", state_text(STATE_UNKNOWN), "Failed to unchunk message body");
1274 } 1277 }
1278 page = tmp;
1275 } 1279 }
1276 1280
1277 if (strlen(string_expect) > 0) { 1281 if (strlen(string_expect) > 0) {
@@ -1374,9 +1378,10 @@ char *unchunk_content(const char *content) {
1374 // https://www.rfc-editor.org/rfc/rfc7230#section-4.1 1378 // https://www.rfc-editor.org/rfc/rfc7230#section-4.1
1375 char *result = NULL; 1379 char *result = NULL;
1376 size_t content_length = strlen(content); 1380 size_t content_length = strlen(content);
1377 char *start_of_chunk, end_of_chunk; 1381 char *start_of_chunk;
1382 char* end_of_chunk;
1378 long size_of_chunk; 1383 long size_of_chunk;
1379 char *pointer = content; 1384 const char *pointer = content;
1380 char *endptr; 1385 char *endptr;
1381 long length_of_chunk = 0; 1386 long length_of_chunk = 0;
1382 size_t overall_size = 0; 1387 size_t overall_size = 0;
@@ -1396,13 +1401,12 @@ char *unchunk_content(const char *content) {
1396 if (verbose) { 1401 if (verbose) {
1397 printf("Chunked content did not start with a number at all (Line: %u)\n", __LINE__); 1402 printf("Chunked content did not start with a number at all (Line: %u)\n", __LINE__);
1398 } 1403 }
1399 return NULL 1404 return NULL;
1400 } 1405 }
1401 1406
1402 // So, we got the length of the chunk 1407 // So, we got the length of the chunk
1403 if (*endptr == ';') { 1408 if (*endptr == ';') {
1404 // Chunk extension starts here 1409 // Chunk extension starts here
1405 // TODO
1406 while (*endptr != '\r') { 1410 while (*endptr != '\r') {
1407 endptr++; 1411 endptr++;
1408 } 1412 }
@@ -1410,7 +1414,8 @@ char *unchunk_content(const char *content) {
1410 1414
1411 start_of_chunk = endptr + 2; 1415 start_of_chunk = endptr + 2;
1412 end_of_chunk = start_of_chunk + size_of_chunk; 1416 end_of_chunk = start_of_chunk + size_of_chunk;
1413 length_of_chunk = end_of_chunk - start_of_chunk; 1417 length_of_chunk = (long)(end_of_chunk - start_of_chunk);
1418 pointer = end_of_chunk + 2; //Next number should be here
1414 1419
1415 if (length_of_chunk == 0) { 1420 if (length_of_chunk == 0) {
1416 // Chunk length is 0, so this is the last one 1421 // Chunk length is 0, so this is the last one
@@ -1442,7 +1447,8 @@ char *unchunk_content(const char *content) {
1442 result_ptr = result_ptr + size_of_chunk; 1447 result_ptr = result_ptr + size_of_chunk;
1443 } 1448 }
1444 1449
1445 return result 1450 result[overall_size] = '\0';
1451 return result;
1446} 1452}
1447 1453
1448/* per RFC 2396 */ 1454/* per RFC 2396 */