[Nagiosplug-checkins] SF.net SVN: nagiosplug:[2049] nagiosplug/trunk/plugins/check_http.c

hweiss at users.sourceforge.net hweiss at users.sourceforge.net
Mon Sep 1 14:20:32 CEST 2008


Revision: 2049
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2049&view=rev
Author:   hweiss
Date:     2008-09-01 12:20:32 +0000 (Mon, 01 Sep 2008)

Log Message:
-----------
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.

Modified Paths:
--------------
    nagiosplug/trunk/plugins/check_http.c

Modified: nagiosplug/trunk/plugins/check_http.c
===================================================================
--- nagiosplug/trunk/plugins/check_http.c	2008-08-25 18:39:27 UTC (rev 2048)
+++ nagiosplug/trunk/plugins/check_http.c	2008-09-01 12:20:32 UTC (rev 2049)
@@ -732,6 +732,22 @@
   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 @@
       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 @@
   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,


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list