public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Return EINVAL for illegal base in strtol Date: Tue, 17 Dec 2019 09:08:00 -0000 [thread overview] Message-ID: <20191217090850.99697.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2635b580ec16aff4230c6ff5fb35c965bf30a251 commit 2635b580ec16aff4230c6ff5fb35c965bf30a251 Author: Keith Packard <keithp@keithp.com> Date: Mon Dec 16 13:55:30 2019 -0800 Return EINVAL for illegal base in strtol Signed-off-by: Keith Packard <keithp@keithp.com> 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;
reply other threads:[~2019-12-17 9:08 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191217090850.99697.qmail@sourceware.org \ --to=corinna@sourceware.org \ --cc=newlib-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).