changeset 159:70da40b41e3a

- Fixed a bug in Cookies_parse_one. Set it to a single return potint too!
author jcid
date Sat, 29 Mar 2008 16:45:17 +0100
parents 5a0ce35806df
children c4badc5f1927
files ChangeLog dpi/cookies.c
diffstat 2 files changed, 31 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Mar 29 16:17:46 2008 +0100
+++ b/ChangeLog	Sat Mar 29 16:45:17 2008 +0100
@@ -84,6 +84,7 @@
  - Added the multipart/form-data encoding method to form submission.
  - Fixed a bug in Html_parse_entity.
  - Fixed a bug in a_Url_cmp.
+ - Fixed a bug in Cookies_parse_one. Set it to a single return potint too!
    Patches: place
 +- Fixed a problem with locally-installed dpis.
  - Added code for optional image loading (nice interface) very advanced!
--- a/dpi/cookies.c	Sat Mar 29 16:17:46 2008 +0100
+++ b/dpi/cookies.c	Sat Mar 29 16:45:17 2008 +0100
@@ -813,6 +813,7 @@
    int num_attr = 0;
    bool_t max_age = FALSE;
    bool_t discard = FALSE;
+   bool_t error = FALSE;
 
    cookie = dNew0(CookieData_t, 1);
    cookie->session_only = TRUE;
@@ -820,6 +821,10 @@
    /* Iterate until there is nothing left of the string OR we come
     * across a comma representing the start of another cookie */
    while (*str != '\0' && *str != ',') {
+      if (error) {
+         str++;
+         continue;
+      }
       /* Skip whitespace */
       while (isspace(*str))
          str++;
@@ -827,9 +832,9 @@
       /* Get attribute */
       attr = Cookies_parse_attr(&str);
       if (!attr) {
-         MSG("Failed to parse cookie attribute!\n");
-         Cookies_free_cookie(cookie);
-         return NULL;
+         MSG("Cannot parse cookie attribute!\n");
+         error = TRUE;
+         continue;
       }
 
       /* Get the value for the attribute and store it */
@@ -857,9 +862,10 @@
                max_age = TRUE;
                dFree(value);
             } else {
-               MSG("Failed to parse cookie value!\n");
-               Cookies_free_cookie(cookie);
-               return NULL;
+               MSG("Cannot parse cookie Max-Age value!\n");
+               dFree(attr);
+               error = TRUE;
+               continue;
             }
          }
       } else if (dStrcasecmp(attr, "Expires") == 0) {
@@ -871,9 +877,10 @@
                cookie->session_only = FALSE;
                dFree(value);
             } else {
-               MSG("Failed to parse cookie value!\n");
-               Cookies_free_cookie(cookie);
-               return NULL;
+               MSG("Cannot parse cookie Expires value!\n");
+               dFree(attr);
+               error = TRUE;
+               continue;
             }
          }
       } else if (dStrcasecmp(attr, "Port") == 0) {
@@ -893,18 +900,19 @@
             cookie->version = strtol(value, NULL, 10);
             dFree(value);
          } else {
-            MSG("Failed to parse cookie value!\n");
-            Cookies_free_cookie(cookie);
-            return NULL;
+            MSG("Cannot parse cookie Version value!\n");
+            dFree(attr);
+            error = TRUE;
+            continue;
          }
       } else if (dStrcasecmp(attr, "Secure") == 0) {
          cookie->secure = TRUE;
       } else {
          /* Oops! this can't be good... */
+         MSG("Cookie contains illegal attribute!\n");
          dFree(attr);
-         Cookies_free_cookie(cookie);
-         MSG("Cookie contains illegal attribute!\n");
-         return NULL;
+         error = TRUE;
+         continue;
       }
 
       dFree(attr);
@@ -913,13 +921,15 @@
 
    *cookie_str = (*str == ',') ? str + 1 : str;
 
-   if (cookie->name && cookie->value) {
-      return cookie;
-   } else {
+   if (!error && (!cookie->name || !cookie->value)) {
       MSG("Cookie missing name and/or value!\n");
+      error = TRUE;
+   }
+   if (error) {
       Cookies_free_cookie(cookie);
-      return NULL;
+      cookie = NULL;
    }
+   return cookie;
 }
 
 /*
@@ -933,7 +943,7 @@
    char *str = cookie_string;
 
    /* The string may contain several cookies separated by comma.
-    * We'll iterate until we've catched them all */
+    * We'll iterate until we've caught them all */
    while (*str) {
       cookie = Cookies_parse_one(url_port, &str);