summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2019-12-16 13:55:30 -0800
committerCorinna Vinschen <corinna@vinschen.de>2019-12-17 10:07:44 +0100
commit2635b580ec16aff4230c6ff5fb35c965bf30a251 (patch)
tree56ea2fd094d7e469abcc0c8c8663e38d3b0e7278
parentd3574fc148721fbaf5be8afa7c32e0bc1aa3bf5c (diff)
downloadcygnal-2635b580ec16aff4230c6ff5fb35c965bf30a251.tar.gz
cygnal-2635b580ec16aff4230c6ff5fb35c965bf30a251.tar.bz2
cygnal-2635b580ec16aff4230c6ff5fb35c965bf30a251.zip
Return EINVAL for illegal base in strtol
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--newlib/libc/stdlib/strtol.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/newlib/libc/stdlib/strtol.c b/newlib/libc/stdlib/strtol.c
index f7572b169..897890fe0 100644
--- a/newlib/libc/stdlib/strtol.c
+++ b/newlib/libc/stdlib/strtol.c
@@ -140,6 +140,11 @@ _strtol_l (struct _reent *rptr, const char *__restrict nptr,
register unsigned long cutoff;
register int neg = 0, any, cutlim;
+ if (base < 0 || base == 1 || base > 36) {
+ errno = EINVAL;
+ return 0;
+ }
+
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
@@ -193,9 +198,9 @@ _strtol_l (struct _reent *rptr, const char *__restrict nptr,
break;
if (c >= base)
break;
- if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
- else {
+ } else {
any = 1;
acc *= base;
acc += c;