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/bug-mktime4.c | |
| parent | 3ae3c4371df5a06d84096f9c6f7bfbe0d3c46a0d (diff) | |
| download | glibc-aaribaud/bugzilla/23789/v4.tar.xz 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/bug-mktime4.c')
| -rw-r--r-- | time/bug-mktime4.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/time/bug-mktime4.c b/time/bug-mktime4.c new file mode 100644 index 0000000000..14d04c669b --- /dev/null +++ b/time/bug-mktime4.c @@ -0,0 +1,27 @@ +#include <time.h> +#include <errno.h> +#include <limits.h> +#include <stdio.h> +#include <string.h> + +static int +do_test (void) +{ + struct tm tm = { .tm_year = INT_MIN, .tm_mon = INT_MIN, .tm_mday = INT_MIN, + .tm_hour = INT_MIN, .tm_min = INT_MIN, .tm_sec = INT_MIN }; + errno = 0; + time_t tt = mktime (&tm); + if (tt != -1) + { + printf ("mktime() should have returned -1, returned %ld\n", (long int) tt); + return 1; + } + if (errno != EOVERFLOW) + { + printf ("mktime() returned -1, errno should be %d (EOVERFLOW) but is %d (%s)\n", EOVERFLOW, errno, strerror(errno)); + return 1; + } + return 0; +} + +#include "support/test-driver.c" |
