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.
This commit is contained in:
parent
81bbee5996
commit
c91e947dbd
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user