浏览代码

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

Holger Weiss 17 年之前
父节点
当前提交
e8c7d1b3d1
共有 1 个文件被更改,包括 21 次插入7 次删除
  1. 21 7
      plugins/check_http.c

+ 21 - 7
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,