summaryrefslogtreecommitdiffstats
path: root/libc/tzcode
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-08-22 14:13:50 -0700
committerElliott Hughes <enh@google.com>2013-08-22 14:18:04 -0700
commit713fe6463e6ff8cb9689aa8ead88c885d25d03aa (patch)
tree76decfb3114af9fbcf85ca6f1c99c94177642023 /libc/tzcode
parentc44205cf717fc8ab8ccaf3631032fa236ba61a86 (diff)
downloadbionic-713fe6463e6ff8cb9689aa8ead88c885d25d03aa.zip
bionic-713fe6463e6ff8cb9689aa8ead88c885d25d03aa.tar.gz
bionic-713fe6463e6ff8cb9689aa8ead88c885d25d03aa.tar.bz2
Apply upstream commit 943a6621866e9d6e654f5cfe1494378c1fb8957a.
Author: Paul Eggert <eggert@cs.ucla.edu> Date: Thu Aug 22 12:47:51 2013 -0700 * localtime.c: Fix another integer overflow bug in mktime. (time2sub): Avoid undefined behavior on time_t overflow. Reported by Elliott Hughes in <http://mm.icann.org/pipermail/tz/2013-August/019580.html>. Bug: 10310929 Change-Id: I3bf26f1f91371552e0a3828457d27e22af55acb2
Diffstat (limited to 'libc/tzcode')
-rw-r--r--libc/tzcode/localtime.c8
-rw-r--r--libc/tzcode/private.h10
2 files changed, 14 insertions, 4 deletions
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c
index d1b49e5..b23eca4 100644
--- a/libc/tzcode/localtime.c
+++ b/libc/tzcode/localtime.c
@@ -1812,14 +1812,14 @@ time2sub(struct tm * const tmp,
} else dir = tmcomp(&mytm, &yourtm);
if (dir != 0) {
if (t == lo) {
- ++t;
- if (t <= lo)
+ if (t == time_t_max)
return WRONG;
+ ++t;
++lo;
} else if (t == hi) {
- --t;
- if (t >= hi)
+ if (t == time_t_min)
return WRONG;
+ --t;
--hi;
}
if (lo > hi)
diff --git a/libc/tzcode/private.h b/libc/tzcode/private.h
index a31a26e..1a938a2 100644
--- a/libc/tzcode/private.h
+++ b/libc/tzcode/private.h
@@ -304,6 +304,16 @@ const char * scheck(const char * string, const char * format);
#define TYPE_SIGNED(type) (((type) -1) < 0)
#endif /* !defined TYPE_SIGNED */
+/* The minimum and maximum finite time values. */
+static time_t const time_t_min =
+ (TYPE_SIGNED(time_t)
+ ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
+ : 0);
+static time_t const time_t_max =
+ (TYPE_SIGNED(time_t)
+ ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
+ : -1);
+
/*
** Since the definition of TYPE_INTEGRAL contains floating point numbers,
** it cannot be used in preprocessor directives.