diff options
author | nectar <nectar@FreeBSD.org> | 2003-11-17 04:19:15 +0000 |
---|---|---|
committer | nectar <nectar@FreeBSD.org> | 2003-11-17 04:19:15 +0000 |
commit | 2736f7d1fc642a97dc6b8e03b68d32c3511ea5ad (patch) | |
tree | ddf328cb014f0f717d0c882dc335946bcf3e5228 /lib | |
parent | 59742d249ee6c2e809621dc611ddbe354e3b3619 (diff) | |
download | FreeBSD-src-2736f7d1fc642a97dc6b8e03b68d32c3511ea5ad.zip FreeBSD-src-2736f7d1fc642a97dc6b8e03b68d32c3511ea5ad.tar.gz |
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.
Diffstat (limited to 'lib')
-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 f69847a..ddf6b57 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; |