File libsoup-CVE-2025-4945.patch of Package libsoup.39491

Backport of https://gitlab.gnome.org/GNOME/libsoup/-/commit/8988379984e33dcc7d3aa58551db13e48755959f

diff -urp libsoup-3.0.4.orig/libsoup/soup-date-utils.c libsoup-3.0.4/libsoup/soup-date-utils.c
--- libsoup-3.0.4.orig/libsoup/soup-date-utils.c	2022-01-05 20:48:16.204507800 -0600
+++ libsoup-3.0.4/libsoup/soup-date-utils.c	2025-06-18 12:19:20.192002093 -0500
@@ -138,7 +138,7 @@ parse_day (int *day, const char **date_s
 	while (*end == ' ' || *end == '-')
 		end++;
 	*date_string = end;
-	return TRUE;
+	return *day >= 1 && *day <= 31;
 }
 
 static inline gboolean
@@ -178,7 +178,7 @@ parse_year (int *year, const char **date
 	while (*end == ' ' || *end == '-')
 		end++;
 	*date_string = end;
-	return TRUE;
+	return *year > 0 && *year < 9999;
 }
 
 static inline gboolean
@@ -202,7 +202,7 @@ parse_time (int *hour, int *minute, int
 	while (*p == ' ')
 		p++;
 	*date_string = p;
-	return TRUE;
+	return *hour >= 0 && *hour < 24 && *minute >= 0 && *minute < 60 && *second >= 0 && *second < 60;
 }
 
 static inline gboolean
@@ -218,9 +218,14 @@ parse_timezone (GTimeZone **timezone, co
 		gulong val;
 		int sign = (**date_string == '+') ? 1 : -1;
 		val = strtoul (*date_string + 1, (char **)date_string, 10);
-		if (**date_string == ':')
-			val = 60 * val + strtoul (*date_string + 1, (char **)date_string, 10);
-		else
+		if (val > 9999)
+			return FALSE;
+		if (**date_string == ':') {
+			gulong val2 = strtoul (*date_string + 1, (char **)date_string, 10);
+			if (val > 99 || val2 > 99)
+				return FALSE;
+			val = 60 * val + val2;
+		} else
 			val =  60 * (val / 100) + (val % 100);
 		offset_minutes = sign * val;
                 utc = (sign == -1) && !val;
@@ -273,7 +278,8 @@ parse_textual_date (const char *date_str
 		if (!parse_month (&month, &date_string) ||
 		    !parse_day (&day, &date_string) ||
 		    !parse_time (&hour, &minute, &second, &date_string) ||
-		    !parse_year (&year, &date_string))
+		    !parse_year (&year, &date_string) ||
+		    !g_date_valid_dmy (day, month, year))
 			return NULL;
 
 		/* There shouldn't be a timezone, but check anyway */
@@ -285,7 +291,8 @@ parse_textual_date (const char *date_str
 		if (!parse_day (&day, &date_string) ||
 		    !parse_month (&month, &date_string) ||
 		    !parse_year (&year, &date_string) ||
-		    !parse_time (&hour, &minute, &second, &date_string))
+		    !parse_time (&hour, &minute, &second, &date_string) ||
+		    !g_date_valid_dmy (day, month, year))
 			return NULL;
 
 		/* This time there *should* be a timezone, but we
diff -urp libsoup-3.0.4.orig/tests/cookies-test.c libsoup-3.0.4/tests/cookies-test.c
--- libsoup-3.0.4.orig/tests/cookies-test.c	2022-01-05 20:48:16.221507800 -0600
+++ libsoup-3.0.4/tests/cookies-test.c	2025-06-18 12:23:11.699485899 -0500
@@ -368,6 +368,15 @@ do_cookies_parsing_nopath_nullorigin (vo
 }
 
 static void
+do_cookies_parsing_int32_overflow (void)
+{
+	SoupCookie *cookie = soup_cookie_parse ("Age=1;expires=3Mar9    999:9:9+ 999999999-age=main=gne=", NULL);
+	g_assert_nonnull (cookie);
+	g_assert_null (soup_cookie_get_expires (cookie));
+	soup_cookie_free (cookie);
+}
+
+static void
 do_get_cookies_empty_host_test (void)
 {
 	SoupCookieJar *jar;
@@ -440,6 +449,7 @@ main (int argc, char **argv)
 	g_test_add_func ("/cookies/accept-policy-subdomains", do_cookies_subdomain_policy_test);
 	g_test_add_func ("/cookies/parsing", do_cookies_parsing_test);
 	g_test_add_func ("/cookies/parsing/no-path-null-origin", do_cookies_parsing_nopath_nullorigin);
+	g_test_add_func ("/cookies/parsing/int32-overflow", do_cookies_parsing_int32_overflow);
 	g_test_add_func ("/cookies/get-cookies/empty-host", do_get_cookies_empty_host_test);
 	g_test_add_func ("/cookies/remove-feature", do_remove_feature_test);
 	g_test_add_func ("/cookies/secure-cookies", do_cookies_strict_secure_test);
openSUSE Build Service is sponsored by