From 1db3424e5f6b0b8cfbf41a287fe48296931be72b Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Sat, 23 Aug 2003 15:07:33 +0000 Subject: - found and fixed memory allocation error in rewritten redir() function git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@695 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_http.c | 112 +++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 58 deletions(-) (limited to 'plugins/check_http.c') diff --git a/plugins/check_http.c b/plugins/check_http.c index 6b952c37..cffe810f 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -475,9 +475,6 @@ check_http (void) int sslerr; #endif - if (verbose) - printf ("%s://%s:%d%s [%s]\n", server_type, server_address, server_port, server_url, host_name); - /* try to connect to the host at the given port number */ #ifdef HAVE_SSL if (use_ssl == TRUE) { @@ -515,9 +512,6 @@ check_http (void) asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); } - if (verbose) - printf ("%s://%s:%d%s\n", server_type, server_address, server_port, server_url); - /* either send http POST data */ if (http_post_data) { asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); @@ -787,69 +781,71 @@ redir (char *pos, char *status_line) while (pos) { - if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) > 0) { - - pos += i; - pos += strspn (pos, " \t\r\n"); + if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) < 1) { - /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ - if (sscanf (pos, HD1, type, addr, port, url) == 4) { - use_ssl = server_type_check (type); - i = atoi (port); - } - - /* URI_HTTP URI_HOST URI_PATH */ - else if (sscanf (pos, HD2, type, addr, url) == 3 ) { - use_ssl = server_type_check (type); - i = server_port_check (use_ssl); - } + pos += (size_t) strcspn (pos, "\r\n"); + pos += (size_t) strspn (pos, "\r\n"); + if (strlen(pos) == 0) + die (STATE_UNKNOWN, + _("UNKNOWN - Could not find redirect location - %s%s\n"), + status_line, (display_html ? "" : "")); + continue; + } - /* URI_HTTP URI_HOST URI_PORT */ - else if(sscanf (pos, HD3, type, addr, port) == 3) { - strcpy (url, HTTP_URL); - use_ssl = server_type_check (type); - i = atoi (port); - } + pos += i; + pos += strspn (pos, " \t\r\n"); - /* URI_HTTP URI_HOST */ - else if(sscanf (pos, HD4, type, addr) == 2) { - strcpy (url, HTTP_URL); - use_ssl = server_type_check (type); - i = server_port_check (use_ssl); - } + url = realloc (url, strcspn (pos, "\r\n")); + if (url == NULL) + die (STATE_UNKNOWN, _("ERROR: could not allocate url\n")); - /* URI_PATH */ - else if (sscanf (pos, HD5, url) == 1) { - /* relative url */ - if ((url[0] != '/')) { - if ((x = strrchr(url, '/'))) - *x = '\0'; - asprintf (&server_url, "%s/%s", server_url, url); - } - i = server_port; - strcpy (type, server_type); - strcpy (addr, host_name); - } + /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ + if (sscanf (pos, HD1, type, addr, port, url) == 4) { + use_ssl = server_type_check (type); + i = atoi (port); + } - else { - die (STATE_UNKNOWN, - _("UNKNOWN - Could not parse redirect location - %s%s\n"), - pos, (display_html ? "" : "")); - } + /* URI_HTTP URI_HOST URI_PATH */ + else if (sscanf (pos, HD2, type, addr, url) == 3 ) { + use_ssl = server_type_check (type); + i = server_port_check (use_ssl); + } - break; + /* URI_HTTP URI_HOST URI_PORT */ + else if(sscanf (pos, HD3, type, addr, port) == 3) { + strcpy (url, HTTP_URL); + use_ssl = server_type_check (type); + i = atoi (port); + } - } else { + /* URI_HTTP URI_HOST */ + else if(sscanf (pos, HD4, type, addr) == 2) { + strcpy (url, HTTP_URL); + use_ssl = server_type_check (type); + i = server_port_check (use_ssl); + } - pos += (size_t) strcspn (pos, "\r\n"); - pos += (size_t) strspn (pos, "\r\n"); - if (strlen(pos) == 0) - die (STATE_UNKNOWN, - _("UNKNOWN - Could not find redirect location - %s%s\n"), - status_line, (display_html ? "" : "")); + /* URI_PATH */ + else if (sscanf (pos, HD5, url) == 1) { + /* relative url */ + if ((url[0] != '/')) { + if ((x = strrchr(url, '/'))) + *x = '\0'; + asprintf (&server_url, "%s/%s", server_url, url); + } + i = server_port; + strcpy (type, server_type); + strcpy (addr, host_name); + } + else { + die (STATE_UNKNOWN, + _("UNKNOWN - Could not parse redirect location - %s%s\n"), + pos, (display_html ? "" : "")); } + break; + } /* end while (pos) */ if (++redir_depth > max_depth) -- cgit v1.2.3