Mercurial > hg > octave-kai > gnulib-hg
changeset 16923:0bce099a6479
mktime: fix integer overflow in 'configure'-time test
* m4/mktime.m4 (gl_FUNC_MKTIME): Do not rely on undefined behavior
after integer overflow. Problem reported by Rich Felker in
<http://lists.gnu.org/archive/html/bug-gnulib/2012-06/msg00257.html>.
Also, don't look for further instances of a bug if we've already
found one instance; this helps 'configure' run faster.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 21 Jun 2012 01:49:15 -0700 |
parents | 937fc0f34278 |
children | 84f589f56820 |
files | ChangeLog m4/mktime.m4 |
diffstat | 2 files changed, 23 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-06-21 Paul Eggert <eggert@cs.ucla.edu> + + mktime: fix integer overflow in 'configure'-time test + * m4/mktime.m4 (gl_FUNC_MKTIME): Do not rely on undefined behavior + after integer overflow. Problem reported by Rich Felker in + <http://lists.gnu.org/archive/html/bug-gnulib/2012-06/msg00257.html>. + Also, don't look for further instances of a bug if we've already + found one instance; this helps 'configure' run faster. + 2012-06-20 John Darrington <john@darrington.wattle.id.au> (tiny change) tmpfile, clean-temp: Fix invocation of GetVersionEx.
--- a/m4/mktime.m4 +++ b/m4/mktime.m4 @@ -1,4 +1,4 @@ -# serial 21 +# serial 22 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2012 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -192,20 +192,23 @@ if (tz_strings[i]) putenv (tz_strings[i]); - for (t = 0; t <= time_t_max - delta; t += delta) + for (t = 0; t <= time_t_max - delta && (result & 1) == 0; t += delta) if (! mktime_test (t)) result |= 1; - if (! (mktime_test ((time_t) 1) - && mktime_test ((time_t) (60 * 60)) - && mktime_test ((time_t) (60 * 60 * 24)))) + if ((result & 2) == 0 + && ! (mktime_test ((time_t) 1) + && mktime_test ((time_t) (60 * 60)) + && mktime_test ((time_t) (60 * 60 * 24)))) result |= 2; - for (j = 1; ; j <<= 1) - if (! bigtime_test (j)) - result |= 4; - else if (INT_MAX / 2 < j) - break; - if (! bigtime_test (INT_MAX)) + for (j = 1; (result & 4) == 0; j <<= 1) + { + if (! bigtime_test (j)) + result |= 4; + if (INT_MAX / 2 < j) + break; + } + if ((result & 8) == 0 && ! bigtime_test (INT_MAX)) result |= 8; } if (! irix_6_4_bug ())