From e8c7d1b3d13b6a40004672ffeab0486f7fb79b71 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 1 Sep 2008 12:20:32 +0000 Subject: [PATCH] Under some circumstances, the 'url' path of a redirection target missed a leading slash. While this was fixed later on, the incomplete 'url' was used for redirection loop detection and error messages. This is now fixed by adding the missing slash immediately. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2049 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_http.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/plugins/check_http.c b/plugins/check_http.c index f54f4ab..4a3d692 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -732,6 +732,22 @@ get_content_length (const char *headers) return (content_length); } +char * +prepend_slash (char *path) +{ + char *newpath; + + if (path[0] == '/') + return path; + + if ((newpath = malloc (strlen(path) + 2)) == NULL) + die (STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n")); + newpath[0] = '/'; + strcpy (newpath + 1, path); + free (path); + return newpath; +} + int check_http (void) { @@ -1112,11 +1128,14 @@ redir (char *pos, char *status_line) die (STATE_UNKNOWN, _("HTTP UNKNOWN - could not allocate url\n")); /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ - if (sscanf (pos, HD1, type, addr, &i, url) == 4) + if (sscanf (pos, HD1, type, addr, &i, url) == 4) { + url = prepend_slash (url); use_ssl = server_type_check (type); + } /* URI_HTTP URI_HOST URI_PATH */ else if (sscanf (pos, HD2, type, addr, url) == 3 ) { + url = prepend_slash (url); use_ssl = server_type_check (type); i = server_port_check (use_ssl); } @@ -1179,12 +1198,7 @@ redir (char *pos, char *status_line) server_address = strdup (addr); free (server_url); - if ((url[0] == '/')) - server_url = strdup (url); - else if (asprintf(&server_url, "/%s", url) == -1) - die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate server_url%s\n"), - display_html ? "" : ""); - free(url); + server_url = url; if ((server_port = i) > MAX_PORT) die (STATE_UNKNOWN, -- 2.30.2