]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cookie: minor parser simplification
authorDaniel Stenberg <daniel@haxx.se>
Mon, 17 Feb 2025 10:15:32 +0000 (11:15 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 17 Feb 2025 12:22:14 +0000 (13:22 +0100)
- parse whitespace before the value is handled
- remove superflous checks from some ISBLANK() loops

Closes #16362

lib/cookie.c

index 2cf5a0de1051f781ad115cc0ab044f87af2ce709..d4ac256600abe8258d4c0014b0ccc9a301c9e947 100644 (file)
@@ -518,7 +518,7 @@ parse_cookie_header(struct Curl_easy *data,
     size_t vlen;
     size_t nlen;
 
-    while(*ptr && ISBLANK(*ptr))
+    while(ISBLANK(*ptr))
       ptr++;
 
     /* we have a <name>=<value> pair or a stand-alone word here */
@@ -536,7 +536,12 @@ parse_cookie_header(struct Curl_easy *data,
         nlen--;
 
       if(*ptr == '=') {
-        vlen = strcspn(++ptr, ";\r\n");
+        ptr++;
+        /* Skip spaces and tabs before the value */
+        while(ISBLANK(*ptr))
+          ptr++;
+
+        vlen = strcspn(ptr, ";\r\n");
         valuep = ptr;
         sep = TRUE;
         ptr = &valuep[vlen];
@@ -545,12 +550,6 @@ parse_cookie_header(struct Curl_easy *data,
         while(vlen && ISBLANK(valuep[vlen-1]))
           vlen--;
 
-        /* Skip leading whitespace from the value */
-        while(vlen && ISBLANK(*valuep)) {
-          valuep++;
-          vlen--;
-        }
-
         /* Reject cookies with a TAB inside the value */
         if(memchr(valuep, '\t', vlen)) {
           infof(data, "cookie contains TAB, dropping");
@@ -769,7 +768,7 @@ parse_cookie_header(struct Curl_easy *data,
       /* this is an "illegal" <what>=<this> pair */
     }
 
-    while(*ptr && ISBLANK(*ptr))
+    while(ISBLANK(*ptr))
       ptr++;
     if(*ptr == ';')
       ptr++;
@@ -1283,7 +1282,7 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
           /* This is a cookie line, get it! */
           lineptr += 11;
           headerline = TRUE;
-          while(*lineptr && ISBLANK(*lineptr))
+          while(ISBLANK(*lineptr))
             lineptr++;
         }