File: headers-Handle-parsing-edge-case.patch

package info (click to toggle)
libsoup3 3.2.3-0%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,496 kB
  • sloc: ansic: 60,347; python: 202; xml: 97; sh: 84; makefile: 25; javascript: 5
file content (59 lines) | stat: -rw-r--r-- 2,161 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From: Patrick Griffis <pgriffis@igalia.com>
Date: Tue, 11 Feb 2025 14:36:26 -0600
Subject: headers: Handle parsing edge case

This version number is specifically crafted to pass sanity checks allowing
it to go one byte out of bounds.

Origin: upstream, 3.6.5, commit:1f509f31b6f8420a3661c3f990424ab7b9164931
Bug: https://gitlab.gnome.org/GNOME/libsoup/-/issues/404
Bug: https://gitlab.gnome.org/GNOME/libsoup/-/issues/407
Bug-CVE: https://security-tracker.debian.org/tracker/CVE-2025-32906
---
 libsoup/soup-headers.c      |  2 +-
 tests/header-parsing-test.c | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libsoup/soup-headers.c b/libsoup/soup-headers.c
index 80272a7..b3b6f28 100644
--- a/libsoup/soup-headers.c
+++ b/libsoup/soup-headers.c
@@ -225,7 +225,7 @@ soup_headers_parse_request (const char          *str,
 	    !g_ascii_isdigit (version[5]))
 		return SOUP_STATUS_BAD_REQUEST;
 	major_version = strtoul (version + 5, &p, 10);
-	if (*p != '.' || !g_ascii_isdigit (p[1]))
+	if (p + 1 >= str + len || *p != '.' || !g_ascii_isdigit (p[1]))
 		return SOUP_STATUS_BAD_REQUEST;
 	minor_version = strtoul (p + 1, &p, 10);
 	version_end = p;
diff --git a/tests/header-parsing-test.c b/tests/header-parsing-test.c
index 2ff97dd..2a572e3 100644
--- a/tests/header-parsing-test.c
+++ b/tests/header-parsing-test.c
@@ -6,6 +6,10 @@ typedef struct {
 	const char *name, *value;
 } Header;
 
+static char unterminated_http_version[] = {
+        'G','E','T',' ','/',' ','H','T','T','P','/','1', '0', '0', '.'
+};
+
 static struct RequestTest {
 	const char *description;
 	const char *bugref;
@@ -383,6 +387,14 @@ static struct RequestTest {
 	  { { NULL } }
 	},
 
+        /* This couldn't be a C string as going one byte over would have been safe. */
+	{ "Long HTTP version terminating at missing minor version", "https://gitlab.gnome.org/GNOME/libsoup/-/issues/404",
+	  unterminated_http_version, sizeof (unterminated_http_version),
+	  SOUP_STATUS_BAD_REQUEST,
+           NULL, NULL, -1,
+	  { { NULL } }
+	},
+
 	{ "Non-HTTP request", NULL,
 	  "GET / SOUP/1.1\r\nHost: example.com\r\n", -1,
 	  SOUP_STATUS_BAD_REQUEST,