sh: Reject integer overflow in number and is_number.

This commit is contained in:
Jilles Tjoelker 2014-08-17 16:40:29 +00:00
parent 1c9c6ea481
commit d53f7f64f7

View File

@ -82,9 +82,17 @@ number(const char *s)
int
is_number(const char *p)
{
do {
if (! is_digit(*p))
const char *q;
if (*p == '\0')
return 0;
while (*p == '0')
p++;
for (q = p; *q != '\0'; q++)
if (! is_digit(*q))
return 0;
} while (*++p != '\0');
if (q - p > 10 ||
(q - p == 10 && memcmp(p, "2147483647", 10) > 0))
return 0;
return 1;
}