Adding d/p/21_check_http_faster_with_large_files from upstream

This commit is contained in:
Jan Wagner 2022-12-27 18:04:16 +00:00
parent f9e79dedec
commit f95110eb99
2 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,37 @@
From 763862a61cf5a7ba1a10f607022aac2434c79f57 Mon Sep 17 00:00:00 2001
From: Danijel Tasov <data@consol.de>
Date: Wed, 21 Dec 2022 14:48:11 +0100
Subject: [PATCH] make check_http faster with larger files
The current implementation becomes exponentially slower with growing
response size.
See also:
https://github.com/nagios-plugins/nagios-plugins/blob/release-2.4.2/plugins/check_http.c#L1199-L1204
---
plugins/check_http.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 41d478163..1835a2d09 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1095,9 +1095,14 @@ check_http (void)
*pos = ' ';
}
buffer[i] = '\0';
- xasprintf (&full_page_new, "%s%s", full_page, buffer);
- free (full_page);
+
+ if ((full_page_new = realloc(full_page, pagesize + i + 1)) == NULL)
+ die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate memory for full_page\n"));
+
+ memmove(&full_page_new[pagesize], buffer, i + 1);
+
full_page = full_page_new;
+
pagesize += i;
if (no_body && document_headers_done (full_page)) {

View file

@ -9,3 +9,4 @@
18_check_icmp_help 18_check_icmp_help
19_check_disk_fs_usage 19_check_disk_fs_usage
20_check_apt_unknown_escape_sequence 20_check_apt_unknown_escape_sequence
21_check_http_faster_with_large_files