diff options
| author | Ahmet Oeztuerk <Ahmet.Oeztuerk@consol.de> | 2025-12-04 16:52:55 +0100 |
|---|---|---|
| committer | Ahmet Oeztuerk <Ahmet.Oeztuerk@consol.de> | 2025-12-04 17:03:57 +0100 |
| commit | e0b30cc6e82113491261c872a371a2fa0b4db3ba (patch) | |
| tree | c32106392c9e12e66fcc9c160624ffa22385e367 | |
| parent | 7ab5b3ba34128949902cb966ab73d84f8fb4113f (diff) | |
| download | monitoring-plugins-e0b30cc6e82113491261c872a371a2fa0b4db3ba.tar.gz | |
append the query string from parsed uri
Check the UriUriA object, and if query string exists append it to the
new_url. Only appends the query part, fragments are still not appended
Function redir parses the new location header value using the
uriParseUriA function already, which populates the query field. This
field was already being printed, but it was not being appended to the
new_url during its construction.
Redirection chain of check_curl --onredirect=follow now mimics the chain
of check_http --onredirect=follow. Tested on the url:
mail.google.com/chat
| -rw-r--r-- | plugins/check_curl.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index e3e514ff..ca6357a7 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -761,7 +761,7 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config | |||
| 761 | } | 761 | } |
| 762 | 762 | ||
| 763 | /* compose new path */ | 763 | /* compose new path */ |
| 764 | /* TODO: handle fragments and query part of URL */ | 764 | /* TODO: handle fragments of URL */ |
| 765 | char *new_url = (char *)calloc(1, DEFAULT_BUFFER_SIZE); | 765 | char *new_url = (char *)calloc(1, DEFAULT_BUFFER_SIZE); |
| 766 | if (uri.pathHead) { | 766 | if (uri.pathHead) { |
| 767 | for (UriPathSegmentA *pathSegment = uri.pathHead; pathSegment; | 767 | for (UriPathSegmentA *pathSegment = uri.pathHead; pathSegment; |
| @@ -772,6 +772,25 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config | |||
| 772 | } | 772 | } |
| 773 | } | 773 | } |
| 774 | 774 | ||
| 775 | /* missing components have null,null in their UriTextRangeA | ||
| 776 | * add query parameters if they exist. | ||
| 777 | */ | ||
| 778 | if (uri.query.first && uri.query.afterLast){ | ||
| 779 | // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat twice | ||
| 780 | size_t current_len = strlen(new_url); | ||
| 781 | size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1; | ||
| 782 | |||
| 783 | const char* query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE); | ||
| 784 | size_t query_str_len = strlen(query_str); | ||
| 785 | |||
| 786 | if (remaining_space >= query_str_len + 1) { | ||
| 787 | strcat(new_url, "?"); | ||
| 788 | strcat(new_url, query_str); | ||
| 789 | }else{ | ||
| 790 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - No space to add query part of size %d to the buffer, buffer has remaining size %d"), query_str_len , current_len ); | ||
| 791 | } | ||
| 792 | } | ||
| 793 | |||
| 775 | if (working_state.serverPort == new_port && | 794 | if (working_state.serverPort == new_port && |
| 776 | !strncmp(working_state.server_address, new_host, MAX_IPV4_HOSTLENGTH) && | 795 | !strncmp(working_state.server_address, new_host, MAX_IPV4_HOSTLENGTH) && |
| 777 | (working_state.host_name && | 796 | (working_state.host_name && |
