@@ -67,7 +67,6 @@ static void freecookie(struct Cookie *co, bool maintoo)
6767{
6868 curlx_free (co -> domain );
6969 curlx_free (co -> path );
70- curlx_free (co -> spath );
7170 curlx_free (co -> name );
7271 curlx_free (co -> value );
7372 if (maintoo )
@@ -227,20 +226,19 @@ static size_t cookiehash(const char * const domain)
227226/*
228227 * cookie path sanitize
229228 */
230- static char * sanitize_cookie_path (const char * cookie_path )
229+ static char * sanitize_cookie_path (const char * cookie_path , size_t len )
231230{
232- size_t len = strlen (cookie_path );
233-
234231 /* some sites send path attribute within '"'. */
235- if (cookie_path [0 ] == '\"' ) {
232+ if (len && ( cookie_path [0 ] == '\"' ) ) {
236233 cookie_path ++ ;
237234 len -- ;
235+
236+ if (len && (cookie_path [len - 1 ] == '\"' ))
237+ len -- ;
238238 }
239- if (len && (cookie_path [len - 1 ] == '\"' ))
240- len -- ;
241239
242240 /* RFC6265 5.2.4 The Path Attribute */
243- if (cookie_path [0 ] != '/' )
241+ if (! len || ( cookie_path [0 ] != '/' ) )
244242 /* Let cookie-path be the default-path. */
245243 return curlx_strdup ("/" );
246244
@@ -393,23 +391,23 @@ static CURLcode storecookie(struct Cookie *co, struct Curl_str *cp,
393391 result = strstore (& co -> value , curlx_str (& cp [COOKIE_VALUE ]),
394392 curlx_strlen (& cp [COOKIE_VALUE ]));
395393 if (!result ) {
396- if (curlx_strlen (& cp [COOKIE_PATH ]))
397- result = strstore (& co -> path , curlx_str (& cp [COOKIE_PATH ]),
398- curlx_strlen (& cp [COOKIE_PATH ]));
394+ size_t plen = 0 ;
395+ if (curlx_strlen (& cp [COOKIE_PATH ])) {
396+ path = curlx_str (& cp [COOKIE_PATH ]);
397+ plen = curlx_strlen (& cp [COOKIE_PATH ]);
398+ }
399399 else if (path ) {
400400 /* No path was given in the header line, set the default */
401401 const char * endslash = strrchr (path , '/' );
402- if (endslash ) {
403- size_t pathlen = (endslash - path + 1 ); /* include end slash */
404- co -> path = Curl_memdup0 (path , pathlen );
405- if (!co -> path )
406- result = CURLE_OUT_OF_MEMORY ;
407- }
402+ if (endslash )
403+ plen = (endslash - path + 1 ); /* include end slash */
404+ else
405+ plen = strlen (path );
408406 }
409407
410- if (! result && co -> path ) {
411- co -> spath = sanitize_cookie_path (co -> path );
412- if (!co -> spath )
408+ if (path ) {
409+ co -> path = sanitize_cookie_path (path , plen );
410+ if (!co -> path )
413411 result = CURLE_OUT_OF_MEMORY ;
414412 }
415413 }
@@ -734,23 +732,17 @@ static CURLcode parse_netscape(struct Cookie *co,
734732 /* The file format allows the path field to remain not filled in */
735733 if (strncmp ("TRUE" , ptr , len ) && strncmp ("FALSE" , ptr , len )) {
736734 /* only if the path does not look like a boolean option! */
737- co -> path = Curl_memdup0 (ptr , len );
735+ co -> path = sanitize_cookie_path (ptr , len );
738736 if (!co -> path )
739737 return CURLE_OUT_OF_MEMORY ;
740- else {
741- co -> spath = sanitize_cookie_path (co -> path );
742- if (!co -> spath )
743- return CURLE_OUT_OF_MEMORY ;
744- }
745738 break ;
746739 }
747- /* this does not look like a path, make one up! */
748- co -> path = curlx_strdup ("/" );
749- if (!co -> path )
750- return CURLE_OUT_OF_MEMORY ;
751- co -> spath = curlx_strdup ("/" );
752- if (!co -> spath )
753- return CURLE_OUT_OF_MEMORY ;
740+ else {
741+ /* this does not look like a path, make one up! */
742+ co -> path = curlx_strdup ("/" );
743+ if (!co -> path )
744+ return CURLE_OUT_OF_MEMORY ;
745+ }
754746 fields ++ ; /* add a field and fall down to secure */
755747 FALLTHROUGH ();
756748 case 3 :
@@ -875,7 +867,7 @@ static bool replace_existing(struct Curl_easy *data,
875867 matching_domains = TRUE;
876868
877869 if (matching_domains && /* the domains were identical */
878- clist -> spath && co -> spath && /* both have paths */
870+ clist -> path && co -> path && /* both have paths */
879871 clist -> secure && !co -> secure && !secure ) {
880872 size_t cllen ;
881873 const char * sep = NULL ;
@@ -887,15 +879,15 @@ static bool replace_existing(struct Curl_easy *data,
887879 * "/loginhelper" is ok.
888880 */
889881
890- DEBUGASSERT (clist -> spath [0 ]);
891- if (clist -> spath [0 ])
892- sep = strchr (clist -> spath + 1 , '/' );
882+ DEBUGASSERT (clist -> path [0 ]);
883+ if (clist -> path [0 ])
884+ sep = strchr (clist -> path + 1 , '/' );
893885 if (sep )
894- cllen = sep - clist -> spath ;
886+ cllen = sep - clist -> path ;
895887 else
896- cllen = strlen (clist -> spath );
888+ cllen = strlen (clist -> path );
897889
898- if (curl_strnequal (clist -> spath , co -> spath , cllen )) {
890+ if (curl_strnequal (clist -> path , co -> path , cllen )) {
899891 infof (data , "cookie '%s' for domain '%s' dropped, would "
900892 "overlay an existing cookie" , co -> name , co -> domain );
901893 return FALSE;
@@ -918,10 +910,10 @@ static bool replace_existing(struct Curl_easy *data,
918910 if (replace_old ) {
919911 /* the domains were identical */
920912
921- if (clist -> spath && co -> spath &&
922- !curl_strequal (clist -> spath , co -> spath ))
913+ if (clist -> path && co -> path &&
914+ !curl_strequal (clist -> path , co -> path ))
923915 replace_old = FALSE;
924- else if (!clist -> spath != !co -> spath )
916+ else if (!clist -> path != !co -> path )
925917 replace_old = FALSE;
926918 }
927919
@@ -1007,7 +999,7 @@ Curl_cookie_add(struct Curl_easy *data,
1007999 * The __Host- prefix requires the cookie to be secure, have a "/" path
10081000 * and not have a domain set.
10091001 */
1010- if (co -> secure && co -> path && strcmp (co -> path , "/" ) == 0 && !co -> tailmatch )
1002+ if (co -> secure && co -> path && ! strcmp (co -> path , "/" ) && !co -> tailmatch )
10111003 ;
10121004 else
10131005 goto fail ;
@@ -1324,7 +1316,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data,
13241316 * now check the left part of the path with the cookies path
13251317 * requirement
13261318 */
1327- if (!co -> spath || pathmatch (co -> spath , path )) {
1319+ if (!co -> path || pathmatch (co -> path , path )) {
13281320
13291321 /*
13301322 * This is a match and we add it to the return-linked-list
0 commit comments