diff options
| author | Jacques Vidrine <nectar@FreeBSD.org> | 2003-11-17 04:19:15 +0000 |
|---|---|---|
| committer | Jacques Vidrine <nectar@FreeBSD.org> | 2003-11-17 04:19:15 +0000 |
| commit | c91e947dbd48907342b1fbffa4f76bdaa3334f0d (patch) | |
| tree | ddf328cb014f0f717d0c882dc335946bcf3e5228 /lib/libc/stdtime | |
| parent | 81bbee59969ccf3738dedd776dae822f7fe3ab6d (diff) | |
Detect range errors when using the %s specifier. Previously, LONG_MAX
was rejected as a range error, while any values less than LONG_MIN
were silently substituted with LONG_MIN. Furthermore, on some
platforms `time_t' has less range than `long' (e.g. alpha), which may
give incorrect results when parsing some strings.
Notes
svn path=/head/; revision=122830
Diffstat (limited to 'lib/libc/stdtime')
| -rw-r--r-- | lib/libc/stdtime/strptime.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index f69847a85bee..ddf6b57e38fc 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -64,7 +64,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <time.h> #include <ctype.h> -#include <limits.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include <pthread.h> @@ -444,11 +444,18 @@ label: case 's': { char *cp; + int sverrno; + long n; time_t t; - t = strtol(buf, &cp, 10); - if (t == LONG_MAX) + sverrno = errno; + errno = 0; + n = strtol(buf, &cp, 10); + if (errno == ERANGE || (long)(t = n) != n) { + errno = sverrno; return 0; + } + errno = sverrno; buf = cp; gmtime_r(&t, tm); *GMTp = 1; |
