hsts: handle adding the same host name again

It will then use the largest expire time of the two entries.
This commit is contained in:
Daniel Stenberg 2022-12-27 11:50:23 +01:00
parent 0bf8b796a0
commit ca02a77f05
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -426,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;
}