Mercurial > gnulib
changeset 39531:e886d9ea220c
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 | 461b806a26b5 |
children | 16d084602a39 |
files | ChangeLog lib/mktime.c |
diffstat | 2 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Aug 31 18:02:48 2018 -0700 +++ b/ChangeLog Sun Sep 02 02:53:31 2018 -0700 @@ -1,3 +1,12 @@ +2018-09-02 Paul Eggert <eggert@cs.ucla.edu> + + 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. + 2018-08-31 Paul Eggert <eggert@cs.ucla.edu> mktime, timegm: simplify glibc time64_t
--- 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);