From db2983da7e8175ca3928998d4547acdf75d55dc0 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 28 Nov 2025 12:21:08 +0100 Subject: Fix/check curl sticky redir (#2188) * check_curl: avoid freeing memory when we don't know where it came from * check_curl: when using -f sticky conserve IPv6 addresses properly When running the check on an ipv6 address with a sticky onredirect policy like in this example: check_curl -6 -H example.com -I ::1 -f sticky It results in a getaddrinfo error: HTTP CRITICAL - Unable to lookup IP address for '[::1]': getaddrinfo returned -3 - Temporary failure in name resolution This happens because in check_http() if the content of server_addr is an ipv6 address enclosing brackets are added and on redirection a subsequent call to check_http() will pass this now bracketed value to getaddrinfo resulting in the error. To work around this, strip the brackets from the address prior to the lookup_host() call. * add Michael Jeanson to thanks --- plugins/check_curl.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'plugins/check_curl.c') diff --git a/plugins/check_curl.c b/plugins/check_curl.c index ba856a11..e3e514ff 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -68,10 +68,6 @@ const char *email = "devel@monitoring-plugins.org"; #include -enum { - MAX_IPV4_HOSTLENGTH = 255, -}; - enum { REGS = 2, }; @@ -789,21 +785,21 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config /* set new values for redirected request */ if (!(config.followsticky & STICKY_HOST)) { - free(working_state.server_address); + // free(working_state.server_address); working_state.server_address = strndup(new_host, MAX_IPV4_HOSTLENGTH); } if (!(config.followsticky & STICKY_PORT)) { working_state.serverPort = (unsigned short)new_port; } - free(working_state.host_name); + // free(working_state.host_name); working_state.host_name = strndup(new_host, MAX_IPV4_HOSTLENGTH); /* reset virtual port */ working_state.virtualPort = working_state.serverPort; free(new_host); - free(working_state.server_url); + // free(working_state.server_url); working_state.server_url = new_url; uriFreeUriMembersA(&uri); -- cgit v1.2.3-74-g34f1