r23725 - gnucash/trunk/src/libqof/qof - Protect GDateTime from getting an out-of-range year at creation.

John Ralls jralls at code.gnucash.org
Sun Jan 19 20:55:04 EST 2014


Author: jralls
Date: 2014-01-19 20:55:04 -0500 (Sun, 19 Jan 2014)
New Revision: 23725
Trac: http://svn.gnucash.org/trac/changeset/23725

Modified:
   gnucash/trunk/src/libqof/qof/gnc-date.c
Log:
Protect GDateTime from getting an out-of-range year at creation.

It can behave badly. See
https://bugzilla.gnome.org/show_bug.cgi?id=721791#c8

Modified: gnucash/trunk/src/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/src/libqof/qof/gnc-date.c	2014-01-19 23:30:58 UTC (rev 23724)
+++ gnucash/trunk/src/libqof/qof/gnc-date.c	2014-01-20 01:55:04 UTC (rev 23725)
@@ -301,6 +301,7 @@
 static void
 gnc_g_date_time_fill_struct_tm (GDateTime *gdt, struct tm* time)
 {
+     memset (time, 0, sizeof (struct tm));
      g_date_time_get_ymd (gdt, &(time->tm_year), &(time->tm_mon), &(time->tm_mday));
      time->tm_sec = g_date_time_get_second (gdt);
      time->tm_min = g_date_time_get_minute (gdt);
@@ -394,6 +395,11 @@
      time64 secs;
 
      ++time->tm_mon;
+     /* GDateTime doesn't protect itself against out-of range years,
+      * so clamp year into GDateTime's range.
+      */
+     if (year < 0) year = -year;
+     if (year > 9999) year % 10000;
 
      normalize_time_component (&(time->tm_sec), &(time->tm_min), 60, 0);
      normalize_time_component (&(time->tm_min), &(time->tm_hour), 60, 0);



More information about the gnucash-changes mailing list