From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99752 invoked by alias); 17 Dec 2019 09:08:51 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 99700 invoked by uid 9078); 17 Dec 2019 09:08:50 -0000 Date: Tue, 17 Dec 2019 09:08:00 -0000 Message-ID: <20191217090850.99697.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Return EINVAL for illegal base in strtol X-Act-Checkin: newlib-cygwin X-Git-Author: Keith Packard X-Git-Refname: refs/heads/master X-Git-Oldrev: d3574fc148721fbaf5be8afa7c32e0bc1aa3bf5c X-Git-Newrev: 2635b580ec16aff4230c6ff5fb35c965bf30a251 X-SW-Source: 2019-q4/txt/msg00024.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2635b580ec16aff4230c6ff5fb35c965bf30a251 commit 2635b580ec16aff4230c6ff5fb35c965bf30a251 Author: Keith Packard Date: Mon Dec 16 13:55:30 2019 -0800 Return EINVAL for illegal base in strtol Signed-off-by: Keith Packard Diff: --- newlib/libc/stdlib/strtol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/newlib/libc/stdlib/strtol.c b/newlib/libc/stdlib/strtol.c index f7572b1..897890f 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;