glibc/time
James Perkins cccc95f28a strptime %z: fix rounding, extend range to +/-9959 [BZ #16141]
Topic: strptime supports a %z input field descriptor, which parses a
time zone offset from UTC time into the broken-out time field tm_gmtoff.

Problems:

1) In the current implementation, the minutes portion calculation is
correct only for minutes evenly divisible by 3. This is because the
minutes value is converted to decimal time, but inadequate precision
leads to rounding which calculates results that are too low for
some values.

For example, due to rounding, a +1159 offset string results in an
incorrect tm_gmtoff of 43128 (== 11 * 3600 + 58.8 * 60) seconds,
instead of 43140 (== 11 * 3600 + 59 * 60) seconds. In contrast,
a +1157 offset (minutes divisible by 3) does not cause the bug,
and results in a correct tm_gmtoff of 43020.

2) strptime's %z specifier will not parse time offsets less than
-1200 or greater than +1200, or if only hour digits are present, less
than -12 or greater than +12. It will return NULL for offsets outside
that range. These limits do not meet historical and modern use cases:

  * Present day exceeds the +1200 limit:
    - Pacific/Auckland (New Zealand) summer time is +1300.
    - Pacific/Kiritimati (Christmas Island) is +1400.
    - Pacific/Apia (Samoa) summer time is +1400.
  * Historical offsets exceeded +1500/-1500.
  * POSIX supports -2459 to +2559.
  * Offsets up to +/-9959 may occasionally be useful.
  * Paul Eggert's notes provide additional detail:
    - https://sourceware.org/ml/libc-alpha/2014-12/msg00068.html
    - https://sourceware.org/ml/libc-alpha/2014-12/msg00072.html

3) tst-strptime2, part of the 'make check' test suite, does not test
for the above problems.

Corrective actions:

1) In time/strptime_l.c, calculate the offset from the hour and
minute portions directly, without the rounding errors introduced by
decimal time.

2) Remove the +/-1200 range limit, permitting strptime to parse offsets
from -9959 through +9959.

3) Add zone offset values to time/tst-strptime2.c.

  * Test minutes evenly divisible by three (+1157) and not evenly
    divisible by three (+1158 and +1159).
  * Test offsets near the old and new range limits (-1201, -1330, -2459,
    -2500, -99, -9959, +1201, +1330, +1400, +1401, +2559, +2600, +99,
    and +9959)

The revised strptime passes all old and new tst-strptime2 tests.
2015-08-28 23:45:51 -04:00
..
sys Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
adjtime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
alt_digit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
asctime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
bug-asctime_r.c [BZ #1468] 2005-10-14 17:20:58 +00:00
bug-asctime.c [BZ #1460] 2005-10-14 15:17:40 +00:00
bug-getdate1.c * time/bug-getdate1.c (do_test): Don't use century values which 2007-12-12 18:23:00 +00:00
bug-mktime1.c [BZ #2821] 2006-09-09 16:56:29 +00:00
clock.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
clocktest.c Define CLOCKS_PER_SEC type to the type clock_t 2015-01-06 04:59:13 -08:00
ctime_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
ctime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
datemsk * time/Makefile (tst-getdate-ENV): Add TZDIR to environment. 2001-07-18 09:43:36 +00:00
Depend * time/Makefile (tst-getdate-ENV): Add TZDIR to environment. 2001-07-18 09:43:36 +00:00
difftime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
dysize.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
era.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
ftime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
getdate.c Fix time/getdate.c build. 2015-02-08 17:45:25 +01:00
getitimer.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gettimeofday.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gmtime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lc-time-cleanup.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
localtime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
Makefile Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mktime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
offtime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
setitimer.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
settimeofday.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
stime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strftime_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strftime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strptime_l.c strptime %z: fix rounding, extend range to +/-9959 [BZ #16141] 2015-08-28 23:45:51 -04:00
strptime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
test_time.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
time.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
time.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
timegm.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
timespec_get.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst_wcsftime.c Update. 1999-06-16 22:55:47 +00:00
tst-ftime_l.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-ftime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-getdate.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-mktime2.c Testsuite #include fixes. 2012-04-02 22:31:32 +02:00
tst-mktime3.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-mktime.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-posixtz.c Replace %ld with %jd and cast to intmax_t 2014-12-30 08:09:43 -08:00
tst-strftime.c (do_test): Add tests for - flag. 2003-05-11 22:41:23 +00:00
tst-strptime2.c strptime %z: fix rounding, extend range to +/-9959 [BZ #16141] 2015-08-28 23:45:51 -04:00
tst-strptime3.c time: ensure failing strptime() tests are reported correctly 2015-03-06 06:06:26 -05:00
tst-strptime-whitespace.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-strptime.c Modify several tests to use test-skeleton.c 2015-08-06 02:59:04 -04:00
tzfile.c Check tzspec_len == 0 in __tzfile_read 2015-04-27 09:57:51 -07:00
tzset.c test-skeleton: Support temporary files without memory leaks [BZ#18333] 2015-04-27 16:19:55 +02:00
Versions Sort Versions files 2013-02-17 16:34:04 +01:00
wcsftime_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
wcsftime.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00