GNOME Bugzilla – Bug 782089
gdatetime: Fix overflow checks when constructing from timestamps
Last modified: 2017-06-15 22:00:48 UTC
Slightly non-trivial patch attached.
Created attachment 350907 [details] [review] gdatetime: Fix overflow checks when constructing from timestamps GDateTime does overflow checks to see if the timestamp being passed in is too big to be represented. However, it only does those after converting from a timestamp to an interval, which involves some multiplications and additions — and hence can overflow, and cause the later bounds check to erroneously succeed. This results in a non-NULL GDateTime being returned which represents completely the wrong date. Fix the overflow checks (do them earlier) and add some unit tests. Signed-off-by: Philip Withnall <withnall@endlessm.com>
Review of attachment 350907 [details] [review]: Looks generally good to me. ::: glib/gdatetime.c @@ +653,3 @@ const GTimeVal *tv) { + if (tv->tv_sec > G_MAXINT64 - 1 || What happens if tv_sec is a 32 bit type? Do we care? ::: glib/tests/gdatetime.c @@ +147,3 @@ +{ + GDateTime *dt; + Would be nice to a reference to the bug, here.
Review of attachment 350907 [details] [review]: ::: glib/gdatetime.c @@ +653,3 @@ const GTimeVal *tv) { + if (tv->tv_sec > G_MAXINT64 - 1 || Whoops, yes, we care. I’ll add some casts to fix this. ::: glib/tests/gdatetime.c @@ +147,3 @@ +{ + GDateTime *dt; + Good point. Added.
t branch -d 782089 Pushed with the requested changes. Thanks for the review! Attachment 350907 [details] pushed as 9374ecc - gdatetime: Fix overflow checks when constructing from timestamps
See https://bugzilla.gnome.org/show_bug.cgi?id=783841 - these new tests fail for 32 bit systems.