summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.d/check_curl_helpers.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-10-30 21:34:50 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-10-30 21:34:50 +0100
commit669edf2afca4d3674019bceb037b0ccc2d938b2a (patch)
tree5e57b02f9c70939fbf027eec53f49d9fdd59afff /plugins/check_curl.d/check_curl_helpers.c
parentbb9fcf5bfaf34aeffd651919b5a14b631b9fceb4 (diff)
downloadmonitoring-plugins-669edf2afca4d3674019bceb037b0ccc2d938b2a.tar.gz
check_curl: accept non standard compliant status line
If the status line from a server ended with '\n' instead of '\r\n' (defined by RFC 9112), check_curl failed to parse it and exited with an alarm. The RFC recommends to be lenient here and this change follows that suggestion.
Diffstat (limited to 'plugins/check_curl.d/check_curl_helpers.c')
-rw-r--r--plugins/check_curl.d/check_curl_helpers.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/plugins/check_curl.d/check_curl_helpers.c b/plugins/check_curl.d/check_curl_helpers.c
index c3c2ba55..d1d282be 100644
--- a/plugins/check_curl.d/check_curl_helpers.c
+++ b/plugins/check_curl.d/check_curl_helpers.c
@@ -4,6 +4,7 @@
4#include <netinet/in.h> 4#include <netinet/in.h>
5#include <netdb.h> 5#include <netdb.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <string.h>
7#include "../utils.h" 8#include "../utils.h"
8#include "check_curl.d/config.h" 9#include "check_curl.d/config.h"
9#include "output.h" 10#include "output.h"
@@ -816,7 +817,8 @@ int curlhelp_parse_statusline(const char *buf, curlhelp_statusline *status_line)
816 buf = start; 817 buf = start;
817 } 818 }
818 819
819 char *first_line_end = strstr(buf, "\r\n"); 820 size_t length_of_first_line = strcspn(buf, "\r\n");
821 const char *first_line_end = &buf[length_of_first_line];
820 if (first_line_end == NULL) { 822 if (first_line_end == NULL) {
821 return -1; 823 return -1;
822 } 824 }
@@ -826,6 +828,7 @@ int curlhelp_parse_statusline(const char *buf, curlhelp_statusline *status_line)
826 if (status_line->first_line == NULL) { 828 if (status_line->first_line == NULL) {
827 return -1; 829 return -1;
828 } 830 }
831
829 memcpy(status_line->first_line, buf, first_line_len); 832 memcpy(status_line->first_line, buf, first_line_len);
830 status_line->first_line[first_line_len] = '\0'; 833 status_line->first_line[first_line_len] = '\0';
831 char *first_line_buf = strdup(status_line->first_line); 834 char *first_line_buf = strdup(status_line->first_line);
@@ -833,23 +836,34 @@ int curlhelp_parse_statusline(const char *buf, curlhelp_statusline *status_line)
833 /* protocol and version: "HTTP/x.x" SP or "HTTP/2" SP */ 836 /* protocol and version: "HTTP/x.x" SP or "HTTP/2" SP */
834 char *temp_string = strtok(first_line_buf, "/"); 837 char *temp_string = strtok(first_line_buf, "/");
835 if (temp_string == NULL) { 838 if (temp_string == NULL) {
839 if (verbose > 1) {
840 printf("%s: no / found\n", __func__);
841 }
836 free(first_line_buf); 842 free(first_line_buf);
837 return -1; 843 return -1;
838 } 844 }
845
839 if (strcmp(temp_string, "HTTP") != 0) { 846 if (strcmp(temp_string, "HTTP") != 0) {
847 if (verbose > 1) {
848 printf("%s: string 'HTTP' not found\n", __func__);
849 }
840 free(first_line_buf); 850 free(first_line_buf);
841 return -1; 851 return -1;
842 } 852 }
843 853
854 // try to find a space in the remaining string?
855 // the space after HTTP/1.1 probably
844 temp_string = strtok(NULL, " "); 856 temp_string = strtok(NULL, " ");
845 if (temp_string == NULL) { 857 if (temp_string == NULL) {
858 if (verbose > 1) {
859 printf("%s: no space after protocol definition\n", __func__);
860 }
846 free(first_line_buf); 861 free(first_line_buf);
847 return -1; 862 return -1;
848 } 863 }
849 864
850 char *temp_string_2; 865 char *temp_string_2;
851 if (strchr(temp_string, '.') != NULL) { 866 if (strchr(temp_string, '.') != NULL) {
852
853 /* HTTP 1.x case */ 867 /* HTTP 1.x case */
854 strtok(temp_string, "."); 868 strtok(temp_string, ".");
855 status_line->http_major = (int)strtol(temp_string, &temp_string_2, 10); 869 status_line->http_major = (int)strtol(temp_string, &temp_string_2, 10);