diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-10-31 12:37:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-31 12:37:42 +0100 |
| commit | 8a4d8bc5d6605851a733ab7cad0e7e097fd3d5d8 (patch) | |
| tree | 76c83fb974bd96a8c5187e8e9b0b775e68068b9a /plugins | |
| parent | bb9fcf5bfaf34aeffd651919b5a14b631b9fceb4 (diff) | |
| parent | 6abf609ed91ab9b8e2c1fac0058d034ceef5f0e8 (diff) | |
| download | monitoring-plugins-8a4d8bc5d6605851a733ab7cad0e7e097fd3d5d8.tar.gz | |
check_curl: accept non standard compliant status line
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_curl.d/check_curl_helpers.c | 20 |
1 files changed, 18 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..d49d8f07 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,10 @@ 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 | // Accept either LF or CRLF as end of line for the status line |
| 821 | // CRLF is the standard (RFC9112), but it is recommended to accept both | ||
| 822 | size_t length_of_first_line = strcspn(buf, "\r\n"); | ||
| 823 | const char *first_line_end = &buf[length_of_first_line]; | ||
| 820 | if (first_line_end == NULL) { | 824 | if (first_line_end == NULL) { |
| 821 | return -1; | 825 | return -1; |
| 822 | } | 826 | } |
| @@ -826,6 +830,7 @@ int curlhelp_parse_statusline(const char *buf, curlhelp_statusline *status_line) | |||
| 826 | if (status_line->first_line == NULL) { | 830 | if (status_line->first_line == NULL) { |
| 827 | return -1; | 831 | return -1; |
| 828 | } | 832 | } |
| 833 | |||
| 829 | memcpy(status_line->first_line, buf, first_line_len); | 834 | memcpy(status_line->first_line, buf, first_line_len); |
| 830 | status_line->first_line[first_line_len] = '\0'; | 835 | status_line->first_line[first_line_len] = '\0'; |
| 831 | char *first_line_buf = strdup(status_line->first_line); | 836 | char *first_line_buf = strdup(status_line->first_line); |
| @@ -833,23 +838,34 @@ int curlhelp_parse_statusline(const char *buf, curlhelp_statusline *status_line) | |||
| 833 | /* protocol and version: "HTTP/x.x" SP or "HTTP/2" SP */ | 838 | /* protocol and version: "HTTP/x.x" SP or "HTTP/2" SP */ |
| 834 | char *temp_string = strtok(first_line_buf, "/"); | 839 | char *temp_string = strtok(first_line_buf, "/"); |
| 835 | if (temp_string == NULL) { | 840 | if (temp_string == NULL) { |
| 841 | if (verbose > 1) { | ||
| 842 | printf("%s: no / found\n", __func__); | ||
| 843 | } | ||
| 836 | free(first_line_buf); | 844 | free(first_line_buf); |
| 837 | return -1; | 845 | return -1; |
| 838 | } | 846 | } |
| 847 | |||
| 839 | if (strcmp(temp_string, "HTTP") != 0) { | 848 | if (strcmp(temp_string, "HTTP") != 0) { |
| 849 | if (verbose > 1) { | ||
| 850 | printf("%s: string 'HTTP' not found\n", __func__); | ||
| 851 | } | ||
| 840 | free(first_line_buf); | 852 | free(first_line_buf); |
| 841 | return -1; | 853 | return -1; |
| 842 | } | 854 | } |
| 843 | 855 | ||
| 856 | // try to find a space in the remaining string? | ||
| 857 | // the space after HTTP/1.1 probably | ||
| 844 | temp_string = strtok(NULL, " "); | 858 | temp_string = strtok(NULL, " "); |
| 845 | if (temp_string == NULL) { | 859 | if (temp_string == NULL) { |
| 860 | if (verbose > 1) { | ||
| 861 | printf("%s: no space after protocol definition\n", __func__); | ||
| 862 | } | ||
| 846 | free(first_line_buf); | 863 | free(first_line_buf); |
| 847 | return -1; | 864 | return -1; |
| 848 | } | 865 | } |
| 849 | 866 | ||
| 850 | char *temp_string_2; | 867 | char *temp_string_2; |
| 851 | if (strchr(temp_string, '.') != NULL) { | 868 | if (strchr(temp_string, '.') != NULL) { |
| 852 | |||
| 853 | /* HTTP 1.x case */ | 869 | /* HTTP 1.x case */ |
| 854 | strtok(temp_string, "."); | 870 | strtok(temp_string, "."); |
| 855 | status_line->http_major = (int)strtol(temp_string, &temp_string_2, 10); | 871 | status_line->http_major = (int)strtol(temp_string, &temp_string_2, 10); |
