From e0b30cc6e82113491261c872a371a2fa0b4db3ba Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Thu, 4 Dec 2025 16:52:55 +0100 Subject: 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 --- plugins/check_curl.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'plugins/check_curl.c') 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 } /* compose new path */ - /* TODO: handle fragments and query part of URL */ + /* TODO: handle fragments of URL */ char *new_url = (char *)calloc(1, DEFAULT_BUFFER_SIZE); if (uri.pathHead) { for (UriPathSegmentA *pathSegment = uri.pathHead; pathSegment; @@ -772,6 +772,25 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config } } + /* missing components have null,null in their UriTextRangeA + * add query parameters if they exist. + */ + if (uri.query.first && uri.query.afterLast){ + // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat twice + size_t current_len = strlen(new_url); + size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1; + + const char* query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE); + size_t query_str_len = strlen(query_str); + + if (remaining_space >= query_str_len + 1) { + strcat(new_url, "?"); + strcat(new_url, query_str); + }else{ + 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 ); + } + } + if (working_state.serverPort == new_port && !strncmp(working_state.server_address, new_host, MAX_IPV4_HOSTLENGTH) && (working_state.host_name && -- cgit v1.2.3-74-g34f1