From 19a49e00d5fab2ac24d36900dc810407fd05d12a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 8 Nov 2018 10:30:36 -0800 Subject: [PATCH 5/7] mktime: fix bug with Y2038 DST transition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [BZ#23789] * time/mktime.c (ranged_convert): On 32-bit platforms, don’t mishandle a DST transition that jumps over the Y2038 boundary. No such DST transitions are known so this is only a theoretical bug, but we might as well do things right. --- ChangeLog | 7 +++++++ time/mktime.c | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 82cdd795ab..939ca140ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2018-11-09 Paul Eggert + mktime: fix bug with Y2038 DST transition + [BZ#23789] + * time/mktime.c (ranged_convert): On 32-bit platforms, don’t + mishandle a DST transition that jumps over the Y2038 boundary. + No such DST transitions are known so this is only a theoretical + bug, but we might as well do things right. + mktime: make more room for overflow [BZ#23789] * time/mktime.c (long_int): Now 4⨯ int, not just 3⨯. diff --git a/time/mktime.c b/time/mktime.c index ffbb5ea171..6d5b8cf838 100644 --- a/time/mktime.c +++ b/time/mktime.c @@ -323,7 +323,7 @@ ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), while (true) { long_int mid = long_int_avg (ok, bad); - if (mid != ok && mid != bad) + if (mid == ok || mid == bad) break; r = convert_time (convert, mid, tp); if (r) @@ -332,6 +332,8 @@ ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), bad = mid; } + *t = ok; + if (!r && ok) { /* The last conversion attempt failed; -- 2.19.1