Backport upstream fix from GNOME/glib MR #5131 for CVE-2026-58011. The patch adds missing range validation to g_date_time_add_full() to prevent creation of invalid GDateTime objects outside the 0001-01-01 to 9999-12-31 range. Also refactors magic day-count constants into named defines for clarity. CVE: CVE-2026-58011 Upstream patches: - https://gitlab.gnome.org/GNOME/glib/-/merge_requests/5131.patch Resolves: RHEL-212196 This commit was backported by Ymir, a Red Hat Enterprise Linux software maintenance AI agent. Assisted-by: Ymir
123 lines
4.2 KiB
Diff
123 lines
4.2 KiB
Diff
From 8cb7ff1e944e9fc8b2fa10df5b9598bf2a53bf1b Mon Sep 17 00:00:00 2001
|
||
From: Philip Withnall <pwithnall@gnome.org>
|
||
Date: Sun, 29 Mar 2026 23:19:47 +0100
|
||
Subject: [PATCH 1/2] gdatetime: Factor out a couple of magic constants
|
||
|
||
This introduces no functional changes, it just makes the code a little
|
||
clearer.
|
||
|
||
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
|
||
---
|
||
glib/gdatetime.c | 9 ++++++---
|
||
1 file changed, 6 insertions(+), 3 deletions(-)
|
||
|
||
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
|
||
index ffdeddd81..4cbc6835f 100644
|
||
--- a/glib/gdatetime.c
|
||
+++ b/glib/gdatetime.c
|
||
@@ -130,7 +130,7 @@ struct _GDateTime
|
||
gint interval;
|
||
|
||
/* 1 is 0001-01-01 in Proleptic Gregorian */
|
||
- gint32 days;
|
||
+ gint32 days; /* in range [MIN_DAYS, MAX_DAYS] */
|
||
|
||
gint ref_count; /* (atomic) */
|
||
};
|
||
@@ -172,6 +172,9 @@ struct _GDateTime
|
||
#define JULIAN_YEAR(d) ((d)->julian / 365.25)
|
||
#define DAYS_PER_PERIOD (G_GINT64_CONSTANT (2914695))
|
||
|
||
+#define MIN_DAYS 1 /* the days count for 0001-01-01 in Proleptic Gregorian */
|
||
+#define MAX_DAYS 3652059 /* the days count for 9999-12-31 in Proleptic Gregorian */
|
||
+
|
||
static const guint16 days_in_months[2][13] =
|
||
{
|
||
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||
@@ -781,7 +784,7 @@ g_date_time_from_instant (GTimeZone *tz,
|
||
datetime->days = instant / USEC_PER_DAY;
|
||
datetime->usec = instant % USEC_PER_DAY;
|
||
|
||
- if (datetime->days < 1 || 3652059 < datetime->days)
|
||
+ if (datetime->days < MIN_DAYS || datetime->days > MAX_DAYS)
|
||
{
|
||
g_date_time_unref (datetime);
|
||
datetime = NULL;
|
||
@@ -817,7 +820,7 @@ g_date_time_deal_with_date_change (GDateTime *datetime)
|
||
gint64 full_time;
|
||
gint64 usec;
|
||
|
||
- if (datetime->days < 1 || datetime->days > 3652059)
|
||
+ if (datetime->days < MIN_DAYS || datetime->days > MAX_DAYS)
|
||
return FALSE;
|
||
|
||
was_dst = g_time_zone_is_dst (datetime->tz, datetime->interval);
|
||
|
||
From c967be13bd6e42f408561d9774da833025501126 Mon Sep 17 00:00:00 2001
|
||
From: Philip Withnall <pwithnall@gnome.org>
|
||
Date: Sun, 29 Mar 2026 23:46:17 +0100
|
||
Subject: [PATCH 2/2] gdatetime: Add missing range validation to
|
||
g_date_time_add_full()
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
Otherwise it’s possible to create a non-`NULL` but invalid `GDateTime`,
|
||
which breaks all kinds of internal assumptions.
|
||
|
||
Spotted by linhlhq as #YWH-PGM9867-191. Thanks to them for providing a
|
||
suggested fix and a test case, which I have adapted and validated.
|
||
|
||
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
|
||
|
||
Fixes: #3917
|
||
---
|
||
glib/gdatetime.c | 4 +++-
|
||
glib/tests/gdatetime.c | 18 ++++++++++++++++++
|
||
2 files changed, 21 insertions(+), 1 deletion(-)
|
||
|
||
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
|
||
index 4cbc6835f..a6b3919f5 100644
|
||
--- a/glib/gdatetime.c
|
||
+++ b/glib/gdatetime.c
|
||
@@ -2022,7 +2022,9 @@ g_date_time_add_full (GDateTime *datetime,
|
||
new->days = full_time / USEC_PER_DAY;
|
||
new->usec = full_time % USEC_PER_DAY;
|
||
|
||
- /* XXX validate */
|
||
+ /* Validate it’s still in the range 0001-01-01 to 9999-12-31 */
|
||
+ if (new->days < MIN_DAYS || new->days > MAX_DAYS)
|
||
+ g_clear_pointer (&new, g_date_time_unref);
|
||
|
||
return new;
|
||
}
|
||
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
|
||
index 7512389e0..32f7e54e7 100644
|
||
--- a/glib/tests/gdatetime.c
|
||
+++ b/glib/tests/gdatetime.c
|
||
@@ -1098,6 +1098,24 @@ test_GDateTime_add_full (void)
|
||
TEST_ADD_FULL (2010, 8, 25, 22, 45, 0,
|
||
0, 1, 6, 1, 25, 0,
|
||
2010, 10, 2, 0, 10, 0);
|
||
+
|
||
+#define TEST_ADD_FULL_ERROR(y,m,d,h,mi,s,ay,am,ad,ah,ami,as) G_STMT_START { \
|
||
+ GDateTime *dt; \
|
||
+ dt = g_date_time_new_utc (y, m, d, h, mi, s); \
|
||
+ g_assert_null (g_date_time_add_full (dt, ay, am, ad, ah, ami, as)); \
|
||
+ g_date_time_unref (dt); \
|
||
+} G_STMT_END
|
||
+
|
||
+ TEST_ADD_FULL_ERROR ( 1, 12, 1, 0, 0, 0,
|
||
+ -1, 0, 0, 0, 0, 0);
|
||
+ TEST_ADD_FULL_ERROR ( 1, 12, 1, 0, 0, 0,
|
||
+ 10000, 0, 0, 0, 0, 0);
|
||
+ TEST_ADD_FULL_ERROR ( 9999, 12, 1, 0, 0, 0,
|
||
+ -10000, 0, 0, 0, 0, 0);
|
||
+ TEST_ADD_FULL_ERROR ( 1, 12, 1, 0, 0, 0,
|
||
+ 0, 0, 3660001, 0, 0, 0);
|
||
+ TEST_ADD_FULL_ERROR ( 9999, 12, 1, 0, 0, 0,
|
||
+ 0, 0, -3660001, 0, 0, 0);
|
||
}
|
||
|
||
static void
|