From: Daniel Stenberg Date: Mon, 17 Feb 2025 10:15:32 +0000 (+0100) Subject: cookie: minor parser simplification X-Git-Tag: curl-8_13_0~445 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0064708f3f1879e0982f5486ebae25e28bee27d8;p=thirdparty%2Fcurl.git cookie: minor parser simplification - parse whitespace before the value is handled - remove superflous checks from some ISBLANK() loops Closes #16362 --- diff --git a/lib/cookie.c b/lib/cookie.c index 2cf5a0de10..d4ac256600 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -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 = 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" = 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++; }