|
| 1 | +From 4584d3ab388a83e2e0753c69437df975b4a13547 Mon Sep 17 00:00:00 2001 |
| 2 | +From: jykanase < [email protected]> |
| 3 | +Date: Sat, 25 Jan 2025 13:44:11 +0000 |
| 4 | +Subject: [PATCH] CVE-2024-9681 |
| 5 | + |
| 6 | +Backported form: https://github.com/curl/curl/commit/a94973805df96269bf |
| 7 | +--- |
| 8 | + extra/curl/curl-8.9.1/lib/hsts.c | 14 ++++++++++---- |
| 9 | + 1 file changed, 10 insertions(+), 4 deletions(-) |
| 10 | + |
| 11 | +diff --git a/extra/curl/curl-8.9.1/lib/hsts.c b/extra/curl/curl-8.9.1/lib/hsts.c |
| 12 | +index 8cd77ae3..6e2599b1 100644 |
| 13 | +--- a/extra/curl/curl-8.9.1/lib/hsts.c |
| 14 | ++++ b/extra/curl/curl-8.9.1/lib/hsts.c |
| 15 | +@@ -249,12 +249,14 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname, |
| 16 | + struct stsentry *Curl_hsts(struct hsts *h, const char *hostname, |
| 17 | + bool subdomain) |
| 18 | + { |
| 19 | ++ struct stsentry *bestsub = NULL; |
| 20 | + if(h) { |
| 21 | + char buffer[MAX_HSTS_HOSTLEN + 1]; |
| 22 | + time_t now = time(NULL); |
| 23 | + size_t hlen = strlen(hostname); |
| 24 | + struct Curl_llist_element *e; |
| 25 | + struct Curl_llist_element *n; |
| 26 | ++ size_t blen = 0; |
| 27 | + |
| 28 | + if((hlen > MAX_HSTS_HOSTLEN) || !hlen) |
| 29 | + return NULL; |
| 30 | +@@ -279,15 +281,19 @@ struct stsentry *Curl_hsts(struct hsts *h, const char *hostname, |
| 31 | + if(ntail < hlen) { |
| 32 | + size_t offs = hlen - ntail; |
| 33 | + if((hostname[offs-1] == '.') && |
| 34 | +- strncasecompare(&hostname[offs], sts->host, ntail)) |
| 35 | +- return sts; |
| 36 | ++ strncasecompare(&hostname[offs], sts->host, ntail) && |
| 37 | ++ (ntail > blen)) { |
| 38 | ++ /* save the tail match with the longest tail */ |
| 39 | ++ bestsub = sts; |
| 40 | ++ blen = ntail; |
| 41 | ++ } |
| 42 | + } |
| 43 | + } |
| 44 | + if(strcasecompare(hostname, sts->host)) |
| 45 | + return sts; |
| 46 | + } |
| 47 | + } |
| 48 | +- return NULL; /* no match */ |
| 49 | ++ return bestsub; |
| 50 | + } |
| 51 | + |
| 52 | + /* |
| 53 | +@@ -439,7 +445,7 @@ static CURLcode hsts_add(struct hsts *h, char *line) |
| 54 | + e = Curl_hsts(h, p, subdomain); |
| 55 | + if(!e) |
| 56 | + result = hsts_create(h, p, subdomain, expires); |
| 57 | +- else { |
| 58 | ++ else if(strcasecompare(p, e->host)) { |
| 59 | + /* the same hostname, use the largest expire time */ |
| 60 | + if(expires > e->expires) |
| 61 | + e->expires = expires; |
| 62 | +-- |
| 63 | +2.45.2 |
| 64 | + |
0 commit comments