mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Rich Felker <dalias@aerifal.cx>
Cc: bug-gnulib@gnu.org, Reuben Thomas <rrt@sc3d.org>,
	musl@lists.openwall.com, Isaac Dunham <idunham@lavabit.com>
Subject: Re: [musl] Re: musl bugs found through gnulib
Date: Thu, 21 Jun 2012 01:52:00 -0700	[thread overview]
Message-ID: <4FE2E0B0.7030507@cs.ucla.edu> (raw)
In-Reply-To: <20120621022116.GX163@brightrain.aerifal.cx>

On 06/20/2012 07:21 PM, Rich Felker wrote:

>>> Replacement of mktime, because of
>>>   checking for working mktime... no
> 
> This test is buggy; it goes into an infinite loop due to integer
> overflow UB, because the condition to break out of the loop is only
> checked when the test does not fail:

Thanks, I pushed the following patch into gnulib:

---
 ChangeLog    |    9 +++++++++
 m4/mktime.m4 |   25 ++++++++++++++-----------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 199b06c..1661a62 100644
--- 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.
diff --git a/m4/mktime.m4 b/m4/mktime.m4
index 5e05dfa..14fcf7f 100644
--- 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 @@ main ()
       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 ())
-- 
1.7.6.5




  reply	other threads:[~2012-06-21  8:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20120609230541.47eac2de@newbook>
     [not found] ` <4FD55156.7050302@cs.ucla.edu>
     [not found]   ` <20120611182202.1ee4d019@newbook>
2012-06-17 22:49     ` Bruno Haible
2012-06-17 23:54       ` Rich Felker
2012-06-18  8:21         ` Szabolcs Nagy
2012-06-18 13:02           ` John Spencer
2012-06-18 14:55             ` Rich Felker
2012-06-18 15:26               ` Szabolcs Nagy
2012-06-18 16:00                 ` Rich Felker
2012-06-19 13:26               ` John Spencer
2012-06-18  0:16       ` [musl] " idunham
2012-06-19  0:11       ` Rich Felker
2012-06-19  2:07         ` [musl] " Eric Blake
2012-06-19  2:52           ` Rich Felker
2012-06-19 11:03             ` musl, fdopen test Bruno Haible
2012-06-19 11:09               ` Jim Meyering
2012-06-20 20:52                 ` Bruno Haible
2012-06-19 10:45         ` musl, printf out-of-memory test Bruno Haible
2012-06-19 19:16           ` Rich Felker
2012-06-19 20:04             ` Bruno Haible
2012-06-19 20:08               ` Rich Felker
2012-06-19 21:17                 ` Bruno Haible
2012-06-20  1:52                   ` Rich Felker
2012-06-20  7:30                     ` Szabolcs Nagy
2012-06-20  9:35                     ` Bruno Haible
2012-06-20 11:00                       ` Jim Meyering
2012-06-21 19:58                         ` Tom Tromey
2012-06-20  3:04       ` Re: musl bugs found through gnulib Rich Felker
2012-06-20  4:10         ` [musl] " Eric Blake
2012-06-20 13:27           ` Rich Felker
2012-06-20  7:32         ` Szabolcs Nagy
2012-06-22 10:39         ` grantpt test Bruno Haible
2012-07-02 22:33         ` [musl] Re: musl bugs found through gnulib Pádraig Brady
2012-06-20 19:28       ` Rich Felker
2012-06-21  2:21         ` Rich Felker
2012-06-21  8:52           ` Paul Eggert [this message]
2012-06-18  0:05 [musl] " idunham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FE2E0B0.7030507@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    --cc=dalias@aerifal.cx \
    --cc=idunham@lavabit.com \
    --cc=musl@lists.openwall.com \
    --cc=rrt@sc3d.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).