From 2bdca0d9f0fb488e4b802492a40606fc22bbcafd Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Tue, 1 Aug 1995 21:38:00 +0000 Subject: strtol and atoi VERY broken in 8bit chars locale, i.e. if you pass something like 38400 it not detect this stuff and produce very big number instead. Fixed by operating with unsigned char and checking for isascii. (secure/telnetd hits by it f.e.) --- lib/libc/stdlib/strtol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/libc/stdlib/strtol.c') diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c index 1a7f7b32cab4..3e6ec70d26d9 100644 --- a/lib/libc/stdlib/strtol.c +++ b/lib/libc/stdlib/strtol.c @@ -55,7 +55,7 @@ strtol(nptr, endptr, base) { register const char *s = nptr; register unsigned long acc; - register int c; + register unsigned char c; register unsigned long cutoff; register int neg = 0, any, cutlim; @@ -102,6 +102,8 @@ strtol(nptr, endptr, base) cutlim = cutoff % (unsigned long)base; cutoff /= (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { + if (!isascii(c)) + break; if (isdigit(c)) c -= '0'; else if (isalpha(c)) -- cgit v1.2.3