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 #include -#include +#include #include #include #include @@ -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;