diff options
author | Holger Weiss <hweiss@users.sourceforge.net> | 2008-09-01 12:20:32 +0000 |
---|---|---|
committer | Holger Weiss <hweiss@users.sourceforge.net> | 2008-09-01 12:20:32 +0000 |
commit | e8c7d1b3d13b6a40004672ffeab0486f7fb79b71 (patch) | |
tree | 89ea0b8e1b1f7697011513013cede7e58c9f988f /plugins | |
parent | 3b4d0bb2922bf26f43d1b0a9c20f46834dacc8d5 (diff) | |
download | monitoring-plugins-e8c7d1b3d13b6a40004672ffeab0486f7fb79b71.tar.gz |
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
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_http.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index f54f4ab8..4a3d692b 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 ? "</A>" : ""); - free(url); + server_url = url; if ((server_port = i) > MAX_PORT) die (STATE_UNKNOWN, |