[glib/glib-2-62: 2/3] gdatetime: Fix error handling in g_date_time_new_week()



commit 7b393fce314c4b303c89dd1ea9c0dbaec7cf43b4
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Sep 24 18:00:53 2019 +0100

    gdatetime: Fix error handling in g_date_time_new_week()
    
    It was possible to pass in (for example) an invalid year to
    g_date_time_new_week(), which would be passed on to g_date_time_new(),
    which would (correctly) return `NULL` — but then
    g_date_time_get_week_number() would try to dereference that.
    
    Includes a test case.
    
    oss-fuzz#17648
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/gdatetime.c       | 2 ++
 glib/tests/gdatetime.c | 1 +
 2 files changed, 3 insertions(+)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 4557e3c76..3be4eba3d 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -1241,6 +1241,8 @@ g_date_time_new_week (GTimeZone *tz, gint year, gint week, gint week_day, gint h
     return NULL;
 
   dt = g_date_time_new (tz, year, 1, 4, 0, 0, 0);
+  if (dt == NULL)
+    return NULL;
   g_date_time_get_week_number (dt, NULL, &jan4_week_day, NULL);
   g_date_time_unref (dt);
 
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index d148cf528..4ecccb347 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -868,6 +868,7 @@ test_GDateTime_new_from_iso8601_2 (void)
     */
     { FALSE, "1719W462 407777-07", 0, 0, 0, 0, 0, 0, 0, 0 },
     { FALSE, "4011090 260528Z", 0, 0, 0, 0, 0, 0, 0, 0 },
+    { FALSE, "0000W011 228214-22", 0, 0, 0, 0, 0, 0, 0, 0 },
   };
   GTimeZone *tz = NULL;
   GDateTime *dt = NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]