summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-12-28 12:56:28 +0100
committerGitHub <noreply@github.com>2025-12-28 12:56:28 +0100
commit9bf9761d8700806892c7c5ffa389121a2b6ac4f1 (patch)
tree0917f9f2f96f325b7aadd9ec8a77fa60b11a8047 /plugins/check_curl.c
parente7dd07c8025b169b7b43b955066a7200d9cdf244 (diff)
parent9c26154698315e06b355b65dd9515419b14b4e0c (diff)
downloadmonitoring-plugins-9bf9761d8700806892c7c5ffa389121a2b6ac4f1.tar.gz
Merge pull request #2198 from inqrphl/fix/check-curl-append-query-string-on-redirect
check_curl: append the query string from parsed uri
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 0aff8b40..bd3f7dce 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 &&