Christian Grothoff пре 17 година
родитељ
комит
a3e03b0e2d
2 измењених фајлова са 36 додато и 5 уклоњено
  1. 2 0
      ChangeLog
  2. 34 5
      src/daemon/connection.c

+ 2 - 0
ChangeLog

@@ -1,5 +1,7 @@
 Fri Dec 26 23:08:04 MST 2008
 	 Fixed broken check for identical connection address. -CG
+	 Making cookie parser more RFC2109 compliant (handle
+	 spaces around key, allow value to be optional). -CG
 
 Sat Dec  6 18:36:17 MST 2008
 	 Added configure option to disable checking for CURL support.

+ 34 - 5
src/daemon/connection.c

@@ -951,8 +951,11 @@ parse_cookie_header (struct MHD_Connection *connection)
   const char *hdr;
   char *cpy;
   char *pos;
+  char *sce;
   char *semicolon;
   char *equals;
+  char *ekill;
+  char old;
   int quotes;
 
   hdr = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "Cookie");
@@ -972,11 +975,37 @@ parse_cookie_header (struct MHD_Connection *connection)
   pos = cpy;
   while (pos != NULL)
     {
-      equals = strstr (pos, "=");
-      if (equals == NULL)
-        break;
-      equals[0] = '\0';
-      equals++;
+      while (*pos == ' ')
+	pos++; /* skip spaces */
+      
+      sce = pos;
+      while ( ( (*sce) != '\0') &&
+	      ( (*sce) != ',') &&
+	      ( (*sce) != ';') &&
+	      ( (*sce) != '=') )
+	sce++;
+      /* remove tailing whitespace (if any) from key */
+      ekill = sce - 1;
+      while ( (*ekill == ' ') &&
+	      (ekill >= pos) )
+	*(ekill--) = '\0';
+      old = *sce;
+      *sce = '\0';
+      if (old != '=')
+	{
+	  /* value part omitted, use empty string... */
+	  if (MHD_NO ==
+	      connection_add_header (connection,
+				     pos,
+				     "",
+				     MHD_COOKIE_KIND))
+	    return MHD_NO;
+	  if (old == '\0')
+	    break;
+	  pos = sce + 1;
+	  continue;
+	}	
+      equals = sce + 1;
       quotes = 0;
       semicolon = equals;
       while ((semicolon[0] != '\0') &&