public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Jeff Johnston <jjohnstn@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] string: Fix buffer overrun in picolibc/newlib/libc/string/strrchr.c (#184) Date: Wed, 13 Oct 2021 20:40:09 +0000 (GMT) [thread overview] Message-ID: <20211013204009.800343858403@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c51f05c59799fd03b15874a9608e613315dcb11c commit c51f05c59799fd03b15874a9608e613315dcb11c Author: Keith Packard <keithp@keithp.com> Date: Mon Oct 11 09:24:54 2021 -0700 string: Fix buffer overrun in picolibc/newlib/libc/string/strrchr.c (#184) Reported by prodisDown: In picolibc/newlib/libc/string/strrchr.c if (i) { while ((s=strchr(s, i))) { last = s; s++; } } else { last = strchr(s, i); } Value (for example 0xFFFFFF00) in if (i) can pass test and then be typecasted to char inside strchr(). Then s++ and then buffer overrun. It can be fixed by preventive typecast i = (int) (char) i; or typecasting inside expression if ((char) i). Fixed by casting to char. Signed-off-by: Keith Packard <keithp@keithp.com> Diff: --- newlib/libc/string/strrchr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/newlib/libc/string/strrchr.c b/newlib/libc/string/strrchr.c index 04897e162..35a7060d2 100644 --- a/newlib/libc/string/strrchr.c +++ b/newlib/libc/string/strrchr.c @@ -34,10 +34,11 @@ strrchr (const char *s, int i) { const char *last = NULL; + char c = i; - if (i) + if (c) { - while ((s=strchr(s, i))) + while ((s=strchr(s, c))) { last = s; s++; @@ -45,8 +46,8 @@ strrchr (const char *s, } else { - last = strchr(s, i); + last = strchr(s, c); } - + return (char *) last; }
reply other threads:[~2021-10-13 20:40 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=20211013204009.800343858403@sourceware.org \ --to=jjohnstn@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).