[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 104/411: altsvc: clone setting in curl_easy_duphandle
From: |
gnunet |
Subject: |
[gnurl] 104/411: altsvc: clone setting in curl_easy_duphandle |
Date: |
Wed, 13 Jan 2021 01:18:39 +0100 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit f93455eb04b57b2d002244bed1f0b59b94c2f0c7
Author: Daniel Stenberg <daniel@haxx.se>
AuthorDate: Sat Sep 5 21:21:26 2020 +0200
altsvc: clone setting in curl_easy_duphandle
The cache content is not duplicated, like other caches, but the setting
and specified file name are.
Test 1908 is extended to verify this somewhat. Since the duplicated
handle gets the same file name, the test unfortunately overwrites the
same file twice (with different contents) which makes it hard to check
automatically.
Closes #5923
---
lib/altsvc.c | 6 ++++--
lib/altsvc.h | 3 ++-
lib/easy.c | 11 +++++++++++
lib/url.c | 5 +----
tests/data/test1908 | 15 ++++++++++++++-
tests/libtest/lib1908.c | 15 +++++++++++++++
tests/unit/unit1654.c | 4 ++--
7 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/lib/altsvc.c b/lib/altsvc.c
index fc56c251b..d3deba3e8 100644
--- a/lib/altsvc.c
+++ b/lib/altsvc.c
@@ -302,11 +302,12 @@ CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const
long ctrl)
* Curl_altsvc_cleanup() frees an altsvc cache instance and all associated
* resources.
*/
-void Curl_altsvc_cleanup(struct altsvcinfo *altsvc)
+void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp)
{
struct Curl_llist_element *e;
struct Curl_llist_element *n;
- if(altsvc) {
+ if(*altsvcp) {
+ struct altsvcinfo *altsvc = *altsvcp;
for(e = altsvc->list.head; e; e = n) {
struct altsvc *as = e->ptr;
n = e->next;
@@ -314,6 +315,7 @@ void Curl_altsvc_cleanup(struct altsvcinfo *altsvc)
}
free(altsvc->filename);
free(altsvc);
+ *altsvcp = NULL; /* clear the pointer */
}
}
diff --git a/lib/altsvc.h b/lib/altsvc.h
index df2750493..1aeb625ab 100644
--- a/lib/altsvc.h
+++ b/lib/altsvc.h
@@ -61,7 +61,7 @@ CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char
*file);
CURLcode Curl_altsvc_save(struct Curl_easy *data,
struct altsvcinfo *asi, const char *file);
CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl);
-void Curl_altsvc_cleanup(struct altsvcinfo *altsvc);
+void Curl_altsvc_cleanup(struct altsvcinfo **altsvc);
CURLcode Curl_altsvc_parse(struct Curl_easy *data,
struct altsvcinfo *altsvc, const char *value,
enum alpnid srcalpn, const char *srchost,
@@ -74,5 +74,6 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi,
#else
/* disabled */
#define Curl_altsvc_save(a,b,c)
+#define Curl_altsvc_cleanup(x)
#endif /* CURL_DISABLE_HTTP || USE_ALTSVC */
#endif /* HEADER_CURL_ALTSVC_H */
diff --git a/lib/easy.c b/lib/easy.c
index a69eb9e56..4da26f914 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -78,6 +78,7 @@
#include "system_win32.h"
#include "http2.h"
#include "dynbuf.h"
+#include "altsvc.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -883,6 +884,15 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy
*data)
goto fail;
}
+#ifdef USE_ALTSVC
+ if(data->asi) {
+ outcurl->asi = Curl_altsvc_init();
+ if(!outcurl->asi)
+ goto fail;
+ if(outcurl->set.str[STRING_ALTSVC])
+ (void)Curl_altsvc_load(outcurl->asi, outcurl->set.str[STRING_ALTSVC]);
+ }
+#endif
/* Clone the resolver handle, if present, for the new handle */
if(Curl_resolver_duphandle(outcurl,
&outcurl->state.resolver,
@@ -930,6 +940,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy
*data)
Curl_dyn_free(&outcurl->state.headerb);
Curl_safefree(outcurl->change.url);
Curl_safefree(outcurl->change.referer);
+ Curl_altsvc_cleanup(&outcurl->asi);
Curl_freeset(outcurl);
free(outcurl);
}
diff --git a/lib/url.c b/lib/url.c
index 2f02a0a16..b3884572d 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -391,11 +391,8 @@ CURLcode Curl_close(struct Curl_easy **datap)
Curl_dyn_free(&data->state.headerb);
Curl_safefree(data->state.ulbuf);
Curl_flush_cookies(data, TRUE);
-#ifdef USE_ALTSVC
Curl_altsvc_save(data, data->asi, data->set.str[STRING_ALTSVC]);
- Curl_altsvc_cleanup(data->asi);
- data->asi = NULL;
-#endif
+ Curl_altsvc_cleanup(&data->asi);
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
Curl_http_auth_cleanup_digest(data);
#endif
diff --git a/tests/data/test1908 b/tests/data/test1908
index bf23ef9fc..00ce98a6a 100644
--- a/tests/data/test1908
+++ b/tests/data/test1908
@@ -8,7 +8,7 @@ CURLINFO_EFFECTIVE_URL
# Server-side
<reply>
<data nocheck="yes">
-HTTP/1.1 200 OK
+HTTP/1.1 200 OK swsbounce
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Content-Type: text/html
@@ -17,6 +17,15 @@ Content-Length: 0
alt-svc: h2="3dbbdetxoyw4nsp6c3cc456oj2ays6s43ezxzsfxxri3h5xqd.example:443";
ma=315360000; persist=1
</data>
+
+# This is the second response
+<data1 nocheck="yes">
+HTTP/1.1 200 OK
+Connection: close
+Content-Length: 0
+alt-svc: h2="second.example:443"; ma=315360000;
+
+</data1>
</reply>
# Client-side
@@ -56,6 +65,10 @@ GET /1908 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
+GET /1908 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
</protocol>
<stripfile>
# strip out the (dynamic) expire date from the file so that the rest
diff --git a/tests/libtest/lib1908.c b/tests/libtest/lib1908.c
index bacbc9710..30e7d8019 100644
--- a/tests/libtest/lib1908.c
+++ b/tests/libtest/lib1908.c
@@ -39,7 +39,22 @@ int test(char *URL)
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(hnd, CURLOPT_ALTSVC, "log/altsvc-1908");
ret = curl_easy_perform(hnd);
+
+ if(!ret) {
+ /* make a copy and check that this also has alt-svc activated */
+ CURL *also = curl_easy_duphandle(hnd);
+ if(also) {
+ ret = curl_easy_perform(also);
+ /* we close the second handle first, which makes it store the alt-svc
+ file only to get overwritten when the next handle is closed! */
+ curl_easy_cleanup(also);
+ }
+ }
+
curl_easy_reset(hnd);
+
+ /* using the same file name for the alt-svc cache, this clobbers the
+ content just written from the 'also' handle */
curl_easy_cleanup(hnd);
}
curl_global_cleanup();
diff --git a/tests/unit/unit1654.c b/tests/unit/unit1654.c
index 79e97631c..6274d0af8 100644
--- a/tests/unit/unit1654.c
+++ b/tests/unit/unit1654.c
@@ -54,7 +54,7 @@ UNITTEST_START
return 1;
result = Curl_altsvc_load(asi, arg);
if(result) {
- Curl_altsvc_cleanup(asi);
+ Curl_altsvc_cleanup(&asi);
return result;
}
curl = curl_easy_init();
@@ -131,7 +131,7 @@ UNITTEST_START
curl_easy_cleanup(curl);
fail:
- Curl_altsvc_cleanup(asi);
+ Curl_altsvc_cleanup(&asi);
return unitfail;
}
UNITTEST_STOP
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnurl] 113/411: url: use blank credentials when using proxy w/o username and password, (continued)
- [gnurl] 113/411: url: use blank credentials when using proxy w/o username and password, gnunet, 2021/01/12
- [gnurl] 136/411: ftp: a 550 response to SIZE returns CURLE_REMOTE_FILE_NOT_FOUND, gnunet, 2021/01/12
- [gnurl] 134/411: curl: make glob_match_url use dynbuf, gnunet, 2021/01/12
- [gnurl] 105/411: CI/azure: add test number to title for display in analytics, gnunet, 2021/01/12
- [gnurl] 87/411: http_proxy: do not crash with HTTPS_PROXY and NO_PROXY set, gnunet, 2021/01/12
- [gnurl] 102/411: tests: remove pipelining tests, gnunet, 2021/01/12
- [gnurl] 126/411: dynbuf: provide curlx_ names for reuse by the curl tool, gnunet, 2021/01/12
- [gnurl] 121/411: HISTORY: mention alt-svc added in 2019, gnunet, 2021/01/12
- [gnurl] 96/411: easygetopt: pass a valid enum to avoid compiler warning, gnunet, 2021/01/12
- [gnurl] 94/411: tool: update --help with categories, gnunet, 2021/01/12
- [gnurl] 104/411: altsvc: clone setting in curl_easy_duphandle,
gnunet <=
- [gnurl] 112/411: travis: add a build using libressl (from git master), gnunet, 2021/01/12
- [gnurl] 131/411: imap: set cselect_bits to CURL_CSELECT_IN initially, gnunet, 2021/01/12
- [gnurl] 128/411: runtests: allow creating files without newlines, gnunet, 2021/01/12
- [gnurl] 147/411: TODO: add PR reference for native IDN support on macOS, gnunet, 2021/01/12
- [gnurl] 155/411: ftp: get rid of the PPSENDF macro, gnunet, 2021/01/12
- [gnurl] 167/411: parsedate: tune the date to epoch conversion, gnunet, 2021/01/12
- [gnurl] 146/411: tool_help.h: update copyright year range, gnunet, 2021/01/12
- [gnurl] 164/411: docs/MQTT: not experimental anymore, gnunet, 2021/01/12
- [gnurl] 178/411: dynbuf: make *addf() not require extra mallocs, gnunet, 2021/01/12
- [gnurl] 157/411: ftp: avoid risk of reading uninitialized integers, gnunet, 2021/01/12