summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorHolger Weiss <hweiss@users.sourceforge.net>2008-09-01 12:20:32 +0000
committerHolger Weiss <hweiss@users.sourceforge.net>2008-09-01 12:20:32 +0000
commite8c7d1b3d13b6a40004672ffeab0486f7fb79b71 (patch)
tree89ea0b8e1b1f7697011513013cede7e58c9f988f /plugins
parent3b4d0bb2922bf26f43d1b0a9c20f46834dacc8d5 (diff)
downloadmonitoring-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.c28
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)
732 return (content_length); 732 return (content_length);
733} 733}
734 734
735char *
736prepend_slash (char *path)
737{
738 char *newpath;
739
740 if (path[0] == '/')
741 return path;
742
743 if ((newpath = malloc (strlen(path) + 2)) == NULL)
744 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n"));
745 newpath[0] = '/';
746 strcpy (newpath + 1, path);
747 free (path);
748 return newpath;
749}
750
735int 751int
736check_http (void) 752check_http (void)
737{ 753{
@@ -1112,11 +1128,14 @@ redir (char *pos, char *status_line)
1112 die (STATE_UNKNOWN, _("HTTP UNKNOWN - could not allocate url\n")); 1128 die (STATE_UNKNOWN, _("HTTP UNKNOWN - could not allocate url\n"));
1113 1129
1114 /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ 1130 /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
1115 if (sscanf (pos, HD1, type, addr, &i, url) == 4) 1131 if (sscanf (pos, HD1, type, addr, &i, url) == 4) {
1132 url = prepend_slash (url);
1116 use_ssl = server_type_check (type); 1133 use_ssl = server_type_check (type);
1134 }
1117 1135
1118 /* URI_HTTP URI_HOST URI_PATH */ 1136 /* URI_HTTP URI_HOST URI_PATH */
1119 else if (sscanf (pos, HD2, type, addr, url) == 3 ) { 1137 else if (sscanf (pos, HD2, type, addr, url) == 3 ) {
1138 url = prepend_slash (url);
1120 use_ssl = server_type_check (type); 1139 use_ssl = server_type_check (type);
1121 i = server_port_check (use_ssl); 1140 i = server_port_check (use_ssl);
1122 } 1141 }
@@ -1179,12 +1198,7 @@ redir (char *pos, char *status_line)
1179 server_address = strdup (addr); 1198 server_address = strdup (addr);
1180 1199
1181 free (server_url); 1200 free (server_url);
1182 if ((url[0] == '/')) 1201 server_url = url;
1183 server_url = strdup (url);
1184 else if (asprintf(&server_url, "/%s", url) == -1)
1185 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate server_url%s\n"),
1186 display_html ? "</A>" : "");
1187 free(url);
1188 1202
1189 if ((server_port = i) > MAX_PORT) 1203 if ((server_port = i) > MAX_PORT)
1190 die (STATE_UNKNOWN, 1204 die (STATE_UNKNOWN,