Skip to content

Commit f5e5a7a

Browse files
[AUTO-CHERRYPICK] libsoup: add patches for CVE-2024-52530, CVE-2024-52531, CVE-2024-52532 - branch main (#11120)
Co-authored-by: Thien Trung Vuong <tvuong@microsoft.com>
1 parent a127791 commit f5e5a7a

4 files changed

Lines changed: 607 additions & 4 deletions

File tree

SPECS/libsoup/CVE-2024-52530.patch

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
From 04df03bc092ac20607f3e150936624d4f536e68b Mon Sep 17 00:00:00 2001
2+
From: Patrick Griffis <pgriffis@igalia.com>
3+
Date: Mon, 8 Jul 2024 12:33:15 -0500
4+
Subject: [PATCH] headers: Strictly don't allow NUL bytes
5+
6+
In the past (2015) this was allowed for some problematic sites. However Chromium also does not allow NUL bytes in either header names or values these days. So this should no longer be a problem.
7+
---
8+
libsoup/soup-headers.c | 15 +++------
9+
tests/header-parsing-test.c | 62 +++++++++++++++++--------------------
10+
2 files changed, 32 insertions(+), 45 deletions(-)
11+
12+
diff --git a/libsoup/soup-headers.c b/libsoup/soup-headers.c
13+
index a0cf351ac..f30ee467a 100644
14+
--- a/libsoup/soup-headers.c
15+
+++ b/libsoup/soup-headers.c
16+
@@ -51,13 +51,14 @@ soup_headers_parse (const char *str, int len, SoupMessageHeaders *dest)
17+
* ignorable trailing whitespace.
18+
*/
19+
20+
+ /* No '\0's are allowed */
21+
+ if (memchr (str, '\0', len))
22+
+ return FALSE;
23+
+
24+
/* Skip over the Request-Line / Status-Line */
25+
headers_start = memchr (str, '\n', len);
26+
if (!headers_start)
27+
return FALSE;
28+
- /* No '\0's in the Request-Line / Status-Line */
29+
- if (memchr (str, '\0', headers_start - str))
30+
- return FALSE;
31+
32+
/* We work on a copy of the headers, which we can write '\0's
33+
* into, so that we don't have to individually g_strndup and
34+
@@ -69,14 +70,6 @@ soup_headers_parse (const char *str, int len, SoupMessageHeaders *dest)
35+
headers_copy[copy_len] = '\0';
36+
value_end = headers_copy;
37+
38+
- /* There shouldn't be any '\0's in the headers already, but
39+
- * this is the web we're talking about.
40+
- */
41+
- while ((p = memchr (headers_copy, '\0', copy_len))) {
42+
- memmove (p, p + 1, copy_len - (p - headers_copy));
43+
- copy_len--;
44+
- }
45+
-
46+
while (*(value_end + 1)) {
47+
name = value_end + 1;
48+
name_end = strchr (name, ':');
49+
diff --git a/tests/header-parsing-test.c b/tests/header-parsing-test.c
50+
index edf8eebb3..715c2c6f2 100644
51+
--- a/tests/header-parsing-test.c
52+
+++ b/tests/header-parsing-test.c
53+
@@ -358,24 +358,6 @@ static struct RequestTest {
54+
}
55+
},
56+
57+
- { "NUL in header name", "760832",
58+
- "GET / HTTP/1.1\r\nHost\x00: example.com\r\n", 36,
59+
- SOUP_STATUS_OK,
60+
- "GET", "/", SOUP_HTTP_1_1,
61+
- { { "Host", "example.com" },
62+
- { NULL }
63+
- }
64+
- },
65+
-
66+
- { "NUL in header value", "760832",
67+
- "GET / HTTP/1.1\r\nHost: example\x00" "com\r\n", 35,
68+
- SOUP_STATUS_OK,
69+
- "GET", "/", SOUP_HTTP_1_1,
70+
- { { "Host", "examplecom" },
71+
- { NULL }
72+
- }
73+
- },
74+
-
75+
/************************/
76+
/*** INVALID REQUESTS ***/
77+
/************************/
78+
@@ -448,6 +430,21 @@ static struct RequestTest {
79+
SOUP_STATUS_EXPECTATION_FAILED,
80+
NULL, NULL, -1,
81+
{ { NULL } }
82+
+ },
83+
+
84+
+ // https://gitlab.gnome.org/GNOME/libsoup/-/issues/377
85+
+ { "NUL in header name", NULL,
86+
+ "GET / HTTP/1.1\r\nHost\x00: example.com\r\n", 36,
87+
+ SOUP_STATUS_BAD_REQUEST,
88+
+ NULL, NULL, -1,
89+
+ { { NULL } }
90+
+ },
91+
+
92+
+ { "NUL in header value", NULL,
93+
+ "HTTP/1.1 200 OK\r\nFoo: b\x00" "ar\r\n", 28,
94+
+ SOUP_STATUS_BAD_REQUEST,
95+
+ NULL, NULL, -1,
96+
+ { { NULL } }
97+
}
98+
};
99+
static const int num_reqtests = G_N_ELEMENTS (reqtests);
100+
@@ -620,22 +617,6 @@ static struct ResponseTest {
101+
{ NULL } }
102+
},
103+
104+
- { "NUL in header name", "760832",
105+
- "HTTP/1.1 200 OK\r\nF\x00oo: bar\r\n", 28,
106+
- SOUP_HTTP_1_1, SOUP_STATUS_OK, "OK",
107+
- { { "Foo", "bar" },
108+
- { NULL }
109+
- }
110+
- },
111+
-
112+
- { "NUL in header value", "760832",
113+
- "HTTP/1.1 200 OK\r\nFoo: b\x00" "ar\r\n", 28,
114+
- SOUP_HTTP_1_1, SOUP_STATUS_OK, "OK",
115+
- { { "Foo", "bar" },
116+
- { NULL }
117+
- }
118+
- },
119+
-
120+
/********************************/
121+
/*** VALID CONTINUE RESPONSES ***/
122+
/********************************/
123+
@@ -768,6 +749,19 @@ static struct ResponseTest {
124+
{ { NULL }
125+
}
126+
},
127+
+
128+
+ // https://gitlab.gnome.org/GNOME/libsoup/-/issues/377
129+
+ { "NUL in header name", NULL,
130+
+ "HTTP/1.1 200 OK\r\nF\x00oo: bar\r\n", 28,
131+
+ -1, 0, NULL,
132+
+ { { NULL } }
133+
+ },
134+
+
135+
+ { "NUL in header value", "760832",
136+
+ "HTTP/1.1 200 OK\r\nFoo: b\x00" "ar\r\n", 28,
137+
+ -1, 0, NULL,
138+
+ { { NULL } }
139+
+ },
140+
};
141+
static const int num_resptests = G_N_ELEMENTS (resptests);
142+
143+
--
144+
GitLab
145+

0 commit comments

Comments
 (0)