diff lib/mktime.c @ 39814:6cbd05e63545

mktime: fix unlikely race+overflow bug Problem reported by Alexandre Oliva in: https://sourceware.org/bugzilla/show_bug.cgi?id=16346 * lib/mktime.c (__mktime_internal): Access *OFFSET only once, to avoid an unlikely race if the compiler delays a load and if this cascades into a signed integer overflow.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 02 Sep 2018 02:53:31 -0700
parents a3f5f4c1daee
children a5c8c624b444
line wrap: on
line diff
--- a/lib/mktime.c	Fri Aug 31 18:02:48 2018 -0700
+++ b/lib/mktime.c	Sun Sep 02 02:53:31 2018 -0700
@@ -394,6 +394,7 @@
   long_int lmday = mday;
   long_int yday = mon_yday + lmday;
 
+  mktime_offset_t off = *offset;
   int negative_offset_guess;
 
   int sec_requested = sec;
@@ -411,7 +412,7 @@
   /* Invert CONVERT by probing.  First assume the same offset as last
      time.  */
 
-  INT_SUBTRACT_WRAPV (0, *offset, &negative_offset_guess);
+  INT_SUBTRACT_WRAPV (0, off, &negative_offset_guess);
   t0 = ydhms_diff (year, yday, hour, min, sec,
 		   EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, negative_offset_guess);