diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-02-09 15:28:03 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-02-09 22:41:49 +0100 |
commit | 02f8de65165ef161a21ace25da3652e1fb13b99b (patch) | |
tree | c85885a4640afecf17d6e92e4df12f887619824c /lib | |
parent | f8f4a9446550f2da7f1dc1892f780aacc7115ec3 (diff) |
altsvc: keep a copy of the file name to survive handle reset
The alt-svc cache survives a call to curl_easy_reset fine, but the file
name to use for saving the cache was cleared. Now the alt-svc cache has
a copy of the file name to survive handle resets.
Added test 1908 to verify.
Reported-by: Craig Andrews
Fixes #4898
Closes #4902
Diffstat (limited to 'lib')
-rw-r--r-- | lib/altsvc.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/altsvc.c b/lib/altsvc.c index 93cc302bd..c05562985 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -185,7 +185,16 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file) { CURLcode result = CURLE_OK; char *line = NULL; - FILE *fp = fopen(file, FOPEN_READTEXT); + FILE *fp; + + /* we need a private copy of the file name so that the altsvc cache file + name survives an easy handle reset */ + free(asi->filename); + asi->filename = strdup(file); + if(!asi->filename) + return CURLE_OUT_OF_MEMORY; + + fp = fopen(file, FOPEN_READTEXT); if(fp) { line = malloc(MAX_ALTSVC_LINE); if(!line) @@ -206,6 +215,7 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file) return result; fail: + Curl_safefree(asi->filename); free(line); fclose(fp); return CURLE_OUT_OF_MEMORY; @@ -299,6 +309,7 @@ void Curl_altsvc_cleanup(struct altsvcinfo *altsvc) n = e->next; altsvc_free(as); } + free(altsvc->filename); free(altsvc); } } @@ -317,6 +328,10 @@ CURLcode Curl_altsvc_save(struct altsvcinfo *altsvc, const char *file) /* no cache activated */ return CURLE_OK; + /* if not new name is given, use the one we stored from the load */ + if(!file && altsvc->filename) + file = altsvc->filename; + if((altsvc->flags & CURLALTSVC_READONLYFILE) || !file || !file[0]) /* marked as read-only, no file or zero length file name */ return CURLE_OK; |