diff options
author | Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr> | 2018-10-24 14:43:06 +0200 |
---|---|---|
committer | Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr> | 2018-11-02 07:03:52 +0100 |
commit | 134ae5ca82d3c5b5b9bab0ad145ffe8b1919a1ae (patch) | |
tree | 18ead43e7adb4d3260bbaed869c6de72350781bd /time/mktime.c | |
parent | 3ae3c4371df5a06d84096f9c6f7bfbe0d3c46a0d (diff) | |
download | glibc-aaribaud/bugzilla/23789/v4.tar glibc-aaribaud/bugzilla/23789/v4.tar.gz glibc-aaribaud/bugzilla/23789/v4.tar.bz2 glibc-aaribaud/bugzilla/23789/v4.zip |
Ensure mktime sets errno on error [BZ #23789]aaribaud/bugzilla/23789/v4
Posix mandates that mktime set errno to EOVERFLOW
on error, but the glibc mktime wasn't doing it so
far.
Fix this and add a test to prevent regressions.
The fix also fixes the same issue in timegm.
Tested with 'make check' on x86-linux-gnu and
i686-linux-gnu.
* time/Makefile: Add bug-mktime4.
* time/bug-mktime4.c: New file.
* time/mktime.c
(__mktime_internal): Set errno to EOVERFLOW on error.
(mktime): Move call to __tzset inside conditional.
Diffstat (limited to 'time/mktime.c')
-rw-r--r-- | time/mktime.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/time/mktime.c b/time/mktime.c index 00f0dec6b4..2e0c467147 100644 --- a/time/mktime.c +++ b/time/mktime.c @@ -49,6 +49,7 @@ # define LEAP_SECONDS_POSSIBLE 1 #endif +#include <errno.h> #include <time.h> #include <limits.h> @@ -435,7 +436,10 @@ __mktime_internal (struct tm *tp, useful than returning -1. */ goto offset_found; else if (--remaining_probes == 0) - return -1; + { + __set_errno (EOVERFLOW); + return -1; + } /* We have a match. Check whether tm.tm_isdst has the requested value, if any. */ @@ -507,7 +511,10 @@ __mktime_internal (struct tm *tp, if (INT_ADD_WRAPV (t, sec_adjustment, &t) || ! (mktime_min <= t && t <= mktime_max) || ! convert_time (convert, t, &tm)) - return -1; + { + __set_errno (EOVERFLOW); + return -1; + } } *tp = tm; @@ -522,13 +529,12 @@ __mktime_internal (struct tm *tp, time_t mktime (struct tm *tp) { +# if defined _LIBC || NEED_MKTIME_WORKING + static mktime_offset_t localtime_offset; /* POSIX.1 8.1.1 requires that whenever mktime() is called, the time zone names contained in the external variable 'tzname' shall be set as if the tzset() function had been called. */ __tzset (); - -# if defined _LIBC || NEED_MKTIME_WORKING - static mktime_offset_t localtime_offset; return __mktime_internal (tp, __localtime_r, &localtime_offset); # else # undef mktime |