summaryrefslogtreecommitdiffstats
path: root/lib/hsts.c
diff options
context:
space:
mode:
authorCurl Upstream <curl-library@lists.haxx.se>2023-02-20 07:24:52 (GMT)
committerBrad King <brad.king@kitware.com>2023-02-21 14:54:46 (GMT)
commit11ba4361aaecf2f1f82ef841146c4c90173d2aca (patch)
tree74bfabf9228b13168d5f822e360cd95a0ac581ae /lib/hsts.c
parentdac458ddbf2b48168779821654a7e69cbd828c14 (diff)
downloadCMake-11ba4361aaecf2f1f82ef841146c4c90173d2aca.zip
CMake-11ba4361aaecf2f1f82ef841146c4c90173d2aca.tar.gz
CMake-11ba4361aaecf2f1f82ef841146c4c90173d2aca.tar.bz2
curl 2023-02-20 (046209e5)
Code extracted from: https://github.com/curl/curl.git at commit 046209e561b7e9b5aab1aef7daebf29ee6e6e8c7 (curl-7_88_1).
Diffstat (limited to 'lib/hsts.c')
-rw-r--r--lib/hsts.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/hsts.c b/lib/hsts.c
index c449120..64cbae1 100644
--- a/lib/hsts.c
+++ b/lib/hsts.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2020 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -39,6 +39,7 @@
#include "parsedate.h"
#include "fopen.h"
#include "rename.h"
+#include "share.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -425,14 +426,23 @@ static CURLcode hsts_add(struct hsts *h, char *line)
if(2 == rc) {
time_t expires = strcmp(date, UNLIMITED) ? Curl_getdate_capped(date) :
TIME_T_MAX;
- CURLcode result;
+ CURLcode result = CURLE_OK;
char *p = host;
bool subdomain = FALSE;
+ struct stsentry *e;
if(p[0] == '.') {
p++;
subdomain = TRUE;
}
- result = hsts_create(h, p, subdomain, expires);
+ /* only add it if not already present */
+ e = Curl_hsts(h, p, subdomain);
+ if(!e)
+ result = hsts_create(h, p, subdomain, expires);
+ else {
+ /* the same host name, use the largest expire time */
+ if(expires > e->expires)
+ e->expires = expires;
+ }
if(result)
return result;
}
@@ -551,4 +561,18 @@ CURLcode Curl_hsts_loadcb(struct Curl_easy *data, struct hsts *h)
return CURLE_OK;
}
+void Curl_hsts_loadfiles(struct Curl_easy *data)
+{
+ struct curl_slist *l = data->set.hstslist;
+ if(l) {
+ Curl_share_lock(data, CURL_LOCK_DATA_HSTS, CURL_LOCK_ACCESS_SINGLE);
+
+ while(l) {
+ (void)Curl_hsts_loadfile(data, data->hsts, l->data);
+ l = l->next;
+ }
+ Curl_share_unlock(data, CURL_LOCK_DATA_HSTS);
+ }
+}
+
#endif /* CURL_DISABLE_HTTP || CURL_DISABLE_HSTS */