diff options
author | Daniel Stenberg <daniel@haxx.se> | 2022-12-22 13:09:16 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2022-12-22 16:06:37 +0100 |
commit | af5999a6742ea90011e7fa08aade7eac9943b76a (patch) | |
tree | 4786ccad2f06062af09de06fea93199ebbf9337f | |
parent | e4505a1915f1bfae71b06636f0690fae2c53c78e (diff) | |
download | curl-af5999a6742ea90011e7fa08aade7eac9943b76a.tar.gz |
urldata: move the cookefilelist to the 'set' struct
The cookiefile entries are set into the handle and should remain set for
the lifetime of the handle so that duplicating it also duplicates the
list. Therefore, the struct field is moved from 'state' to 'set'.
Fixes #10133
Closes #10134
-rw-r--r-- | lib/cookie.c | 20 | ||||
-rw-r--r-- | lib/easy.c | 12 | ||||
-rw-r--r-- | lib/setopt.c | 12 | ||||
-rw-r--r-- | lib/transfer.c | 6 | ||||
-rw-r--r-- | lib/url.c | 1 | ||||
-rw-r--r-- | lib/urldata.h | 8 | ||||
-rw-r--r-- | tests/data/test1905 | 2 |
7 files changed, 24 insertions, 37 deletions
diff --git a/lib/cookie.c b/lib/cookie.c index bccf2e888..25d73954e 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -329,7 +329,7 @@ static char *sanitize_cookie_path(const char *cookie_path) */ void Curl_cookie_loadfiles(struct Curl_easy *data) { - struct curl_slist *list = data->state.cookielist; + struct curl_slist *list = data->set.cookielist; if(list) { Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); while(list) { @@ -347,8 +347,6 @@ void Curl_cookie_loadfiles(struct Curl_easy *data) data->cookies = newcookies; list = list->next; } - curl_slist_free_all(data->state.cookielist); /* clean up list */ - data->state.cookielist = NULL; /* don't do this again! */ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); } } @@ -1800,12 +1798,10 @@ void Curl_flush_cookies(struct Curl_easy *data, bool cleanup) CURLcode res; if(data->set.str[STRING_COOKIEJAR]) { - if(data->state.cookielist) { - /* If there is a list of cookie files to read, do it first so that - we have all the told files read before we write the new jar. - Curl_cookie_loadfiles() LOCKS and UNLOCKS the share itself! */ - Curl_cookie_loadfiles(data); - } + /* If there is a list of cookie files to read, do it first so that + we have all the told files read before we write the new jar. + Curl_cookie_loadfiles() LOCKS and UNLOCKS the share itself! */ + Curl_cookie_loadfiles(data); Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); @@ -1816,12 +1812,6 @@ void Curl_flush_cookies(struct Curl_easy *data, bool cleanup) data->set.str[STRING_COOKIEJAR], curl_easy_strerror(res)); } else { - if(cleanup && data->state.cookielist) { - /* since nothing is written, we can just free the list of cookie file - names */ - curl_slist_free_all(data->state.cookielist); /* clean up list */ - data->state.cookielist = NULL; - } Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); } diff --git a/lib/easy.c b/lib/easy.c index d7da09601..2a94bc52a 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -913,11 +913,9 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data) goto fail; } - /* duplicate all values in 'change' */ - if(data->state.cookielist) { - outcurl->state.cookielist = - Curl_slist_duplicate(data->state.cookielist); - if(!outcurl->state.cookielist) + if(data->set.cookielist) { + outcurl->set.cookielist = Curl_slist_duplicate(data->set.cookielist); + if(!outcurl->set.cookielist) goto fail; } #endif @@ -1003,8 +1001,8 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data) if(outcurl) { #ifndef CURL_DISABLE_COOKIES - curl_slist_free_all(outcurl->state.cookielist); - outcurl->state.cookielist = NULL; + curl_slist_free_all(outcurl->set.cookielist); + outcurl->set.cookielist = NULL; #endif Curl_safefree(outcurl->state.buffer); Curl_dyn_free(&outcurl->state.headerb); diff --git a/lib/setopt.c b/lib/setopt.c index b77e95b4e..46b8a99f3 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -760,18 +760,18 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) return CURLE_BAD_FUNCTION_ARGUMENT; /* append the cookie file name to the list of file names, and deal with them later */ - cl = curl_slist_append(data->state.cookielist, argptr); + cl = curl_slist_append(data->set.cookielist, argptr); if(!cl) { - curl_slist_free_all(data->state.cookielist); - data->state.cookielist = NULL; + curl_slist_free_all(data->set.cookielist); + data->set.cookielist = NULL; return CURLE_OUT_OF_MEMORY; } - data->state.cookielist = cl; /* store the list for later use */ + data->set.cookielist = cl; /* store the list for later use */ } else { /* clear the list of cookie files */ - curl_slist_free_all(data->state.cookielist); - data->state.cookielist = NULL; + curl_slist_free_all(data->set.cookielist); + data->set.cookielist = NULL; if(!data->share || !data->share->cookies) { /* throw away all existing cookies if this isn't a shared cookie diff --git a/lib/transfer.c b/lib/transfer.c index ba0410fc5..90d9c7b18 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -1389,11 +1389,9 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) else data->state.infilesize = 0; -#ifndef CURL_DISABLE_COOKIES /* If there is a list of cookie files to read, do it now! */ - if(data->state.cookielist) - Curl_cookie_loadfiles(data); -#endif + Curl_cookie_loadfiles(data); + /* If there is a list of host pairs to deal with */ if(data->state.resolve) result = Curl_loadhostpairs(data); @@ -431,6 +431,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_dyn_free(&data->state.headerb); Curl_safefree(data->state.ulbuf); Curl_flush_cookies(data, TRUE); + curl_slist_free_all(data->set.cookielist); /* clean up list */ Curl_altsvc_save(data, data->asi, data->set.str[STRING_ALTSVC]); Curl_altsvc_cleanup(&data->asi); Curl_hsts_save(data, data->hsts, data->set.str[STRING_HSTS]); diff --git a/lib/urldata.h b/lib/urldata.h index 3d7545c68..152226c4f 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -1403,10 +1403,6 @@ struct UrlState { is this */ char *url; /* work URL, copied from UserDefined */ char *referer; /* referer string */ -#ifndef CURL_DISABLE_COOKIES - struct curl_slist *cookielist; /* list of cookie files set by - curl_easy_setopt(COOKIEFILE) calls */ -#endif struct curl_slist *resolve; /* set to point to the set.resolve list when this should be dealt with in pretransfer */ #ifndef CURL_DISABLE_HTTP @@ -1661,6 +1657,10 @@ struct UserDefined { void *prereq_userp; /* pre-initial request user data */ void *seek_client; /* pointer to pass to the seek callback */ +#ifndef CURL_DISABLE_COOKIES + struct curl_slist *cookielist; /* list of cookie files set by + curl_easy_setopt(COOKIEFILE) calls */ +#endif #ifndef CURL_DISABLE_HSTS curl_hstsread_callback hsts_read; void *hsts_read_userp; diff --git a/tests/data/test1905 b/tests/data/test1905 index 4d04f8183..b185b24ed 100644 --- a/tests/data/test1905 +++ b/tests/data/test1905 @@ -50,8 +50,8 @@ Accept: */* # https://curl.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. -%HOSTIP FALSE /we/want/ FALSE 0 secondcookie present %HOSTIP FALSE /we/want/ FALSE 0 foobar name +%HOSTIP FALSE /we/want/ FALSE 0 secondcookie present </file> </verify> </testcase> |