monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[monit-dev] [monit] r281 committed - * HTTP and URL protocol tests: Fixe


From: monit
Subject: [monit-dev] [monit] r281 committed - * HTTP and URL protocol tests: Fixed a problem where HTTP protocol...
Date: Fri, 24 Sep 2010 18:50:58 +0000

Revision: 281
Author: janhenrik.haukeland
Date: Fri Sep 24 11:47:07 2010
Log: * HTTP and URL protocol tests: Fixed a problem where HTTP protocol
  tests using a specific request always failed. This bug may also
  affect URL tests. The problem was caused by faulty URL encoding. In
  the process of fixing this bug the new feature that allowed slash in
  service names has been reverted and instead will be added in a later
  release.

http://code.google.com/p/monit/source/detail?r=281

Modified:
 /trunk/CHANGES.txt
 /trunk/control.c
 /trunk/http/cervlet.c
 /trunk/p.y
 /trunk/util.c
 /trunk/util.h

=======================================
--- /trunk/CHANGES.txt  Thu Sep 23 07:18:15 2010
+++ /trunk/CHANGES.txt  Fri Sep 24 11:47:07 2010
@@ -1,4 +1,4 @@
-                     CHANGES version 5.2
+                     CHANGES version 5.2.1

            This file summarizes changes made since 5.0

@@ -7,6 +7,18 @@
           https://savannah.nongnu.org/bugs/?group=monit


+Version 5.2.1
+
+BUGFIXES:
+
+* HTTP and URL protocol tests: Fixed a problem where HTTP protocol
+  tests using a specific request always failed. This bug may also
+  affect URL tests. The problem was caused by faulty URL encoding. In
+  the process of fixing this bug the new feature that allowed slash in
+  service names has been reverted and instead will be added in a later
+  release.
+
+
 Version 5.2

 NEW FEATURES AND FUNCTIONS:
=======================================
--- /trunk/control.c    Fri Sep 24 09:13:19 2010
+++ /trunk/control.c    Fri Sep 24 11:47:07 2010
@@ -100,7 +100,6 @@
   int status, content_length = 0;
   Socket_T s;
   char *auth;
-  char *svc;
   char buf[STRLEN];

   ASSERT(S);
@@ -119,7 +118,6 @@

   /* Send request */
   auth = Util_getBasicAuthHeaderMonit();
-  svc = Util_encodeServiceName((char *)S);
   if (socket_print(s,
         "POST /%s HTTP/1.0\r\n"
         "Content-Type: application/x-www-form-urlencoded\r\n"
@@ -127,7 +125,7 @@
         "%s"
         "\r\n"
         "action=%s",
-        svc,
+        S,
         strlen("action=") + strlen(action),
         auth ? auth : "",
         action) < 0) {
@@ -175,7 +173,6 @@
     rv = TRUE;
 err1:
   FREE(auth);
-  FREE(svc);
   socket_free(&s);

   return rv;
=======================================
--- /trunk/http/cervlet.c       Fri Sep 24 09:13:19 2010
+++ /trunk/http/cervlet.c       Fri Sep 24 11:47:07 2010
@@ -714,15 +714,12 @@
   ActionRate_T ar;
   ServiceGroup_T sg;
   ServiceGroupMember_T sgm;
-  char *svc;
   char *status;
   char buf[STRLEN];

   ASSERT(s);

-  svc = Util_encodeServiceName(s->name);
-  HEAD(svc, s->name, Run.polltime)
-  FREE(svc);
+  HEAD(s->name, s->name, Run.polltime)

   out_print(res,
     "<p><br><h3>%s status</h3><br>"
@@ -880,7 +877,6 @@

 static void do_home_system(HttpRequest req, HttpResponse res) {
   Service_T s = Run.system;
-  char *svc = Util_encodeServiceName(s->name);
   char *status = get_service_status_html(s);

   out_print(res,
@@ -903,9 +899,7 @@
     "<tr bgcolor=\"#EFEFEF\">"
     "<td align=\"left\"><a href='%s'>%s</a></td>"
     "<td align=\"left\">%s</td>",
-    svc, s->name,
-    status);
-  FREE(svc);
+    s->name, s->name, status);
   FREE(status);

   if(Run.doprocess) {
@@ -938,7 +932,6 @@
 static void do_home_process(HttpRequest req, HttpResponse res) {

   Service_T      s;
-  char          *svc;
   char          *status;
   int            on= TRUE;
   int            header= TRUE;
@@ -971,15 +964,12 @@
     }

     status= get_service_status_html(s);
-    svc = Util_encodeServiceName(s->name);
     out_print(res,
       "<tr %s>"
       "<td width=\"20%%\"><a href='%s'>%s</a></td>"
       "<td align=\"left\">%s</td>",
       on?"bgcolor=\"#EFEFEF\"":"",
-      svc, s->name,
-      status);
-    FREE(svc);
+      s->name, s->name, status);
     FREE(status);

     if(!Util_hasServiceStatus(s)) {
@@ -1027,7 +1017,6 @@

 static void do_home_filesystem(HttpRequest req, HttpResponse res) {
   Service_T     s;
-  char         *svc;
   char         *status;
   int           on= TRUE;
   int           header= TRUE;
@@ -1053,15 +1042,12 @@
     }

     status= get_service_status_html(s);
-    svc = Util_encodeServiceName(s->name);
     out_print(res,
       "<tr %s>"
       "<td width=\"20%%\"><a href='%s'>%s</a></td>"
       "<td align=\"left\">%s</td>",
       on?"bgcolor=\"#EFEFEF\"":"",
-      svc, s->name,
-      status);
-    FREE(svc);
+      s->name, s->name,status);
     FREE(status);

     if(!Util_hasServiceStatus(s)) {
@@ -1108,7 +1094,6 @@
 static void do_home_file(HttpRequest req, HttpResponse res) {

   Service_T  s;
-  char      *svc;
   char      *status;
   int        on= TRUE;
   int        header= TRUE;
@@ -1136,15 +1121,12 @@
     }

     status= get_service_status_html(s);
-    svc = Util_encodeServiceName(s->name);
     out_print(res,
       "<tr %s>"
       "<td width=\"20%%\"><a href='%s'>%s</a></td>"
       "<td align=\"left\">%s</td>",
       on?"bgcolor=\"#EFEFEF\"":"",
-      svc, s->name,
-      status);
-    FREE(svc);
+      s->name, s->name,status);
     FREE(status);

     if(!Util_hasServiceStatus(s)) {
@@ -1184,7 +1166,6 @@
 static void do_home_fifo(HttpRequest req, HttpResponse res) {

   Service_T  s;
-  char      *svc;
   char      *status;
   int        on= TRUE;
   int        header= TRUE;
@@ -1211,15 +1192,12 @@
     }

     status= get_service_status_html(s);
-    svc = Util_encodeServiceName(s->name);
     out_print(res,
       "<tr %s>"
       "<td width=\"20%%\"><a href='%s'>%s</a></td>"
       "<td align=\"left\">%s</td>",
       on?"bgcolor=\"#EFEFEF\"":"",
-      svc, s->name,
-      status);
-    FREE(svc);
+      s->name, s->name,status);
     FREE(status);

     if(!Util_hasServiceStatus(s)) {
@@ -1256,7 +1234,6 @@
 static void do_home_directory(HttpRequest req, HttpResponse res) {

   Service_T        s;
-  char            *svc;
   char            *status;
   int              on= TRUE;
   int              header= TRUE;
@@ -1283,15 +1260,12 @@
     }

     status= get_service_status_html(s);
-    svc = Util_encodeServiceName(s->name);
     out_print(res,
       "<tr %s>"
       "<td width=\"20%%\"><a href='%s'>%s</a></td>"
       "<td align=\"left\">%s</td>",
       on?"bgcolor=\"#EFEFEF\"":"",
-      svc, s->name,
-      status);
-    FREE(svc);
+      s->name, s->name,status);
     FREE(status);

     if(!Util_hasServiceStatus(s)) {
@@ -1330,7 +1304,6 @@
   Service_T  s;
   Icmp_T     icmp;
   Port_T     port;
-  char      *svc;
   char      *status;
   int        on= TRUE;
   int        header= TRUE;
@@ -1355,15 +1328,12 @@
     }

     status= get_service_status_html(s);
-    svc = Util_encodeServiceName(s->name);
     out_print(res,
       "<tr %s>"
       "<td width=\"20%%\"><a href='%s'>%s</a></td>"
       "<td align=\"left\">%s</td>",
       on?"bgcolor=\"#EFEFEF\"":"",
-      svc, s->name,
-      status);
-    FREE(svc);
+      s->name, s->name,status);
     FREE(status);

     if(!Util_hasServiceStatus(s)) {
@@ -1489,7 +1459,6 @@


 static void print_buttons(HttpRequest req, HttpResponse res, Service_T s) {
-  char *svc;

   if(is_readonly(req)) {
     /*
@@ -1498,8 +1467,6 @@
     return;
   }

-  svc = Util_encodeServiceName(s->name);
-
   out_print(res, "<table cellspacing=16><tr nowrap><td><font size=+1>");
   /* Start program */
   if(s->start)
@@ -1507,32 +1474,30 @@
                 "<td><form method=POST action=%s>"
                 "<input type=hidden value='start' name=action>"
"<input type=submit value='Start service' style='font-size: "
-                "12pt'></form></td>", svc);
+                "12pt'></form></td>", s->name);
   /* Stop program */
   if(s->stop)
       out_print(res,
                 "<td><form method=POST action=%s>"
                 "<input type=hidden value='stop' name=action>"
"<input type=submit value='Stop service' style='font-size: "
-                "12pt'></form></td>", svc);
+                "12pt'></form></td>", s->name);
   /* Restart program */
   if(s->start && s->stop)
       out_print(res,
                 "<td><form method=POST action=%s>"
                 "<input type=hidden value='restart' name=action>"
"<input type=submit value='Restart service' style='font-size: "
-                "12pt'></form></td>", svc);
+                "12pt'></form></td>", s->name);
   /* (un)monitor */
   out_print(res,
             "<td><form method=POST action=%s>"
             "<input type=hidden value='%s' name=action>"
             "<input type=submit value='%s' style='font-size: 12pt'>"
             "</form></td></tr></table>",
-            svc,
+            s->name,
             s->monitor?"unmonitor":"monitor",
             s->monitor?"Disable monitoring":"Enable monitoring");
-
-  FREE(svc);
 }


=======================================
--- /trunk/p.y  Mon Sep 20 14:15:39 2010
+++ /trunk/p.y  Fri Sep 24 11:47:07 2010
@@ -3339,6 +3339,8 @@

   if (Util_existService(name) || (current && IS(name, current->name)))
     yyerror2("service name conflict, %s already defined", name);
+  if (name && *name == '/')
+          yyerror2("service name '%s' must not start with '/' -- ", name);
 }


=======================================
--- /trunk/util.c       Fri Sep 24 09:13:19 2010
+++ /trunk/util.c       Fri Sep 24 11:47:07 2010
@@ -134,7 +134,6 @@
 static char   x2c(char *hex);
 static char  *is_str_defined(char *);
 static void   printevents(unsigned int);
-static int    is_url_unsafe(unsigned char *);
 #ifdef HAVE_LIBPAM
 #ifdef SOLARIS
static int PAMquery(int, struct pam_message **, struct pam_response **, void *);
@@ -152,6 +151,63 @@
 };


+/* Unsafe URL characters: <>\"#%{}|\\^[] ` */
+static const unsigned char urlunsafe[256] = {
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
+        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
+};
+
+
+static const unsigned char b2x[][256] = {
+        "00", "01", "02", "03", "04", "05", "06", "07",
+        "08", "09", "0A", "0B", "0C", "0D", "0E", "0F",
+        "10", "11", "12", "13", "14", "15", "16", "17",
+        "18", "19", "1A", "1B", "1C", "1D", "1E", "1F",
+        "20", "21", "22", "23", "24", "25", "26", "27",
+        "28", "29", "2A", "2B", "2C", "2D", "2E", "2F",
+        "30", "31", "32", "33", "34", "35", "36", "37",
+        "38", "39", "3A", "3B", "3C", "3D", "3E", "3F",
+        "40", "41", "42", "43", "44", "45", "46", "47",
+        "48", "49", "4A", "4B", "4C", "4D", "4E", "4F",
+        "50", "51", "52", "53", "54", "55", "56", "57",
+        "58", "59", "5A", "5B", "5C", "5D", "5E", "5F",
+        "60", "61", "62", "63", "64", "65", "66", "67",
+        "68", "69", "6A", "6B", "6C", "6D", "6E", "6F",
+        "70", "71", "72", "73", "74", "75", "76", "77",
+        "78", "79", "7A", "7B", "7C", "7D", "7E", "7F",
+        "80", "81", "82", "83", "84", "85", "86", "87",
+        "88", "89", "8A", "8B", "8C", "8D", "8E", "8F",
+        "90", "91", "92", "93", "94", "95", "96", "97",
+        "98", "99", "9A", "9B", "9C", "9D", "9E", "9F",
+        "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7",
+        "A8", "A9", "AA", "AB", "AC", "AD", "AE", "AF",
+        "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7",
+        "B8", "B9", "BA", "BB", "BC", "BD", "BE", "BF",
+        "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7",
+        "C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF",
+        "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
+        "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF",
+        "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7",
+        "E8", "E9", "EA", "EB", "EC", "ED", "EE", "EF",
+        "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
+        "F8", "F9", "FA", "FB", "FC", "FD", "FE", "FF"
+};
+
+
 /**
  *  General purpose utility methods.
  *
@@ -1479,36 +1535,43 @@
     LogError("checksum: file %s is not regular file\n", file);
   return FALSE;
 }
+
+
+int Util_isurlsafe(const char *url) {
+        int i;
+        ASSERT(url && *url);
+        for (i = 0; url[i]; i++)
+                if (urlunsafe[(unsigned char)url[i]])
+                        return FALSE;
+        return TRUE;
+}


 /**
- * Escape an uri string converting unsafe characters to a hex (%xx)
+ * Escape an url string converting unsafe characters to a hex (%xx)
  * representation.  The caller must free the returned string.
- * @param uri an uri string
+ * @param url an url string
  * @return the escaped string
  */
-char *Util_urlEncode(char *uri) {
-
-  register int x, y;
-  unsigned char *str;
-  static unsigned char hexchars[]= "0123456789ABCDEF";
-
-  ASSERT(uri);
-
- str= (unsigned char *)xcalloc(sizeof(unsigned char), 3 * strlen(uri) + 1);
-
-  for(x = 0, y = 0; uri[x]; x++, y++) {
-    if(is_url_unsafe((unsigned char*) &uri[x])) {
-      str[y++] = '%';
-      str[y++] = hexchars[(unsigned char) uri[x] >> 4];
-      str[y] = hexchars[(unsigned char) uri[x] & 0xf];
-    } else str[y]= (unsigned char)uri[x];
-  }
-
-  str[y] = '\0';
-
-  return ((char *) str);
-
+char *Util_urlEncode(char *url) {
+        char *escaped = NULL;
+        if (url) {
+                char *p;
+                int i, n;
+                for (n = i = 0; url[i]; i++)
+                        if (urlunsafe[(unsigned char)(url[i])])
+                                n += 2;
+                p = escaped = xmalloc(i + n + 1);
+                for (; *url; url++, p++) {
+                        if (urlunsafe[(unsigned char)(*p = *url)]) {
+                                *p++= '%';
+                                *p++= b2x[(unsigned char)(*url)][0];
+                                *p = b2x[(unsigned char)(*url)][1];
+                        }
+                }
+                *p = 0;
+        }
+        return escaped;
 }


@@ -1519,25 +1582,24 @@
  * @return A pointer to the unescaped <code>url</code>string
  */
 char *Util_urlDecode(char *url) {
-
-  register int x,y;
-
-  if(!(url&&*url)) return url;
-  Util_replace(url, '+', ' ');
-  for(x=0,y=0;url[y];++x,++y) {
-    if((url[x] = url[y]) == '%') {
-      url[x]= x2c(&url[y+1]);
-      y+=2;
-    }
-    while(url[x] == '/' && url[y+1] == '/') {
-      y++;
-    }
-  }
-  url[x]= 0;
-  return url;
+       if (url && *url) {
+                register int x, y;
+                for (x = 0, y = 0; url[y]; x++, y++) {
+                        if ((url[x] = url[y]) == '+')
+                                url[x] = ' ';
+                        else if (url[x] == '%') {
+                                if (! (url[x + 1] && url[x + 2]))
+                                        break;
+                                url[x] = x2c(url + y + 1);
+                                y += 2;
+                        }
+                }
+                url[x] = 0;
+        }
+       return url;
 }

-
+// NOTE: To be used to URL encode service names when ready
 char *Util_encodeServiceName(char *name) {
         int i;
         ASSERT(name);
@@ -2206,29 +2268,6 @@
 static char *is_str_defined(char *s) {
   return ((s&&*s)?s:"(not defined)");
 }
-
-
-/**
- * Returns TRUE if the given char is url unsafe
- * @param c A unsigned char
- * @return TRUE if the char is in the set of unsafe URL Characters
- */
-static int is_url_unsafe(unsigned char *c) {
-  int i;
-  static unsigned char unsafe[]= "<>\"#{}|\\^~[]`";
-
-  ASSERT(c);
-
-  if(33>*c || *c>176)
-    return TRUE;
-  if(*c=='%') {
-    if( isxdigit(*(c + 1)) && isxdigit(*(c + 2)) ) return FALSE;
-    return TRUE;
-  }
-  for(i=0; unsafe[i]; i++)
-    if(*c==unsafe[i]) return TRUE;
-  return FALSE;
-}


 /**
=======================================
--- /trunk/util.h       Fri Sep 24 09:13:19 2010
+++ /trunk/util.h       Fri Sep 24 11:47:07 2010
@@ -294,12 +294,19 @@


 /**
- * Escape an uri string converting unsafe characters to a hex (%xx)
+ * Returns true if url contains url safe characters otherwise false
+ * @param url an url string to test
+ * @return true if url is url safe otherwise false
+ */
+int Util_isurlsafe(const char *url);
+
+/**
+ * Escape an url string converting unsafe characters to a hex (%xx)
  * representation.  The caller must free the returned string.
- * @param uri an uri string
+ * @param url an url string
  * @return the escaped string
  */
-char *Util_urlEncode(char *uri);
+char *Util_urlEncode(char *url);


 /**



reply via email to

[Prev in Thread] Current Thread [Next in Thread]