diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-11-28 12:21:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-28 12:21:08 +0100 |
| commit | db2983da7e8175ca3928998d4547acdf75d55dc0 (patch) | |
| tree | 45bbbb2e6f6cf17f8058cb5428a5f0fb43d94b94 /plugins/check_curl.c | |
| parent | 2f96b82c9b67ca1aad6cd584a9c458d060bdd4bb (diff) | |
| download | monitoring-plugins-db2983da7e8175ca3928998d4547acdf75d55dc0.tar.gz | |
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
Diffstat (limited to 'plugins/check_curl.c')
| -rw-r--r-- | plugins/check_curl.c | 10 |
1 files changed, 3 insertions, 7 deletions
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 | |||
| @@ -69,10 +69,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 69 | #include <netdb.h> | 69 | #include <netdb.h> |
| 70 | 70 | ||
| 71 | enum { | 71 | enum { |
| 72 | MAX_IPV4_HOSTLENGTH = 255, | ||
| 73 | }; | ||
| 74 | |||
| 75 | enum { | ||
| 76 | REGS = 2, | 72 | REGS = 2, |
| 77 | }; | 73 | }; |
| 78 | 74 | ||
| @@ -789,21 +785,21 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config | |||
| 789 | /* set new values for redirected request */ | 785 | /* set new values for redirected request */ |
| 790 | 786 | ||
| 791 | if (!(config.followsticky & STICKY_HOST)) { | 787 | if (!(config.followsticky & STICKY_HOST)) { |
| 792 | free(working_state.server_address); | 788 | // free(working_state.server_address); |
| 793 | working_state.server_address = strndup(new_host, MAX_IPV4_HOSTLENGTH); | 789 | working_state.server_address = strndup(new_host, MAX_IPV4_HOSTLENGTH); |
| 794 | } | 790 | } |
| 795 | if (!(config.followsticky & STICKY_PORT)) { | 791 | if (!(config.followsticky & STICKY_PORT)) { |
| 796 | working_state.serverPort = (unsigned short)new_port; | 792 | working_state.serverPort = (unsigned short)new_port; |
| 797 | } | 793 | } |
| 798 | 794 | ||
| 799 | free(working_state.host_name); | 795 | // free(working_state.host_name); |
| 800 | working_state.host_name = strndup(new_host, MAX_IPV4_HOSTLENGTH); | 796 | working_state.host_name = strndup(new_host, MAX_IPV4_HOSTLENGTH); |
| 801 | 797 | ||
| 802 | /* reset virtual port */ | 798 | /* reset virtual port */ |
| 803 | working_state.virtualPort = working_state.serverPort; | 799 | working_state.virtualPort = working_state.serverPort; |
| 804 | 800 | ||
| 805 | free(new_host); | 801 | free(new_host); |
| 806 | free(working_state.server_url); | 802 | // free(working_state.server_url); |
| 807 | working_state.server_url = new_url; | 803 | working_state.server_url = new_url; |
| 808 | 804 | ||
| 809 | uriFreeUriMembersA(&uri); | 805 | uriFreeUriMembersA(&uri); |
