5 Star 0 Fork 6

OpenCloudOS Stream/curl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CVE-2024-9681.patch 3.52 KB
一键复制 编辑 原始数据 按行查看 历史
ZoeDong 提交于 2024-11-14 11:42 . Fix CVE-2024-9681
From cbfe4770253b7aca27696d02021a45b99b658a01 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Wed, 9 Oct 2024 10:04:35 +0200
Subject: [PATCH] hsts: improve subdomain handling
- on load, only replace existing HSTS entries if there is a full host
match
- on matching, prefer a full host match and secondary the longest tail
subdomain match
Closes #15210
---
Conflicts:
lib/hsts.c
reference: https://github.com/curl/curl/commit/60d8663afb0fb7f113
---
lib/hsts.c | 28 +++++++++++++++++-----------
tests/data/test1660 | 2 +-
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/lib/hsts.c b/lib/hsts.c
index 7ecf0042a..4a773143d 100644
--- a/lib/hsts.c
+++ b/lib/hsts.c
@@ -249,12 +249,14 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname,
struct stsentry *Curl_hsts(struct hsts *h, const char *hostname,
bool subdomain)
{
+ struct stsentry *bestsub = NULL;
if(h) {
char buffer[MAX_HSTS_HOSTLEN + 1];
time_t now = time(NULL);
size_t hlen = strlen(hostname);
struct Curl_llist_element *e;
struct Curl_llist_element *n;
+ size_t blen = 0;
if((hlen > MAX_HSTS_HOSTLEN) || !hlen)
return NULL;
@@ -267,6 +269,7 @@ struct stsentry *Curl_hsts(struct hsts *h, const char *hostname,
for(e = h->list.head; e; e = n) {
struct stsentry *sts = e->ptr;
+ size_t ntail;
n = e->next;
if(sts->expires <= now) {
/* remove expired entries */
@@ -274,20 +277,23 @@ struct stsentry *Curl_hsts(struct hsts *h, const char *hostname,
hsts_free(sts);
continue;
}
- if(subdomain && sts->includeSubDomains) {
- size_t ntail = strlen(sts->host);
- if(ntail < hlen) {
- size_t offs = hlen - ntail;
- if((hostname[offs-1] == '.') &&
- strncasecompare(&hostname[offs], sts->host, ntail))
- return sts;
+ ntail = strlen(sts->host);
+ if((subdomain && sts->includeSubDomains) && (ntail < hlen)) {
+ size_t offs = hlen - ntail;
+ if((hostname[offs-1] == '.') &&
+ strncasecompare(&hostname[offs], sts->host, ntail) &&
+ (ntail > blen)) {
+ /* save the tail match with the longest tail */
+ bestsub = sts;
+ blen = ntail;
}
}
- if(strcasecompare(hostname, sts->host))
+ /* avoid strcasecompare because the host name is not null terminated */
+ if((hlen == ntail) && strncasecompare(hostname, sts->host, hlen))
return sts;
}
}
- return NULL; /* no match */
+ return bestsub;
}
/*
@@ -439,8 +445,8 @@ static CURLcode hsts_add(struct hsts *h, char *line)
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 */
+ else if(strcasecompare(p, e->host)) {
+ /* the same hostname, use the largest expire time */
if(expires > e->expires)
e->expires = expires;
}
diff --git a/tests/data/test1660 b/tests/data/test1660
index f86126d19..4b6f9615c 100644
--- a/tests/data/test1660
+++ b/tests/data/test1660
@@ -52,7 +52,7 @@ this.example [this.example]: 1548400797
Input 12: error 43
Input 13: error 43
Input 14: error 43
-3.example.com [example.com]: 1569905261 includeSubDomains
+3.example.com [3.example.com]: 1569905261 includeSubDomains
3.example.com [example.com]: 1569905261 includeSubDomains
foo.example.com [example.com]: 1569905261 includeSubDomains
'foo.xample.com' is not HSTS
--
2.41.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/opencloudos-stream/curl.git
git@gitee.com:opencloudos-stream/curl.git
opencloudos-stream
curl
curl
master

搜索帮助