From: PkmX <pkmx.tw@gmail.com>
To: newlib@sourceware.org
Subject: [PATCH] riscv: fix integer wraparound in memcpy
Date: Fri, 24 Jul 2020 19:07:45 +0800 [thread overview]
Message-ID: <CACSh3m3euJOWd94oEpV6MWUUqm4Ehg3bt_x4y-HZTX0j=qZs7w@mail.gmail.com> (raw)
This patch fixes a bug in RISC-V's memcpy implementation where an
integer wraparound occurs when src + size < 8 * sizeof(long), causing
the word-sized copy loop to be incorrectly entered.
Signed-off-by: Chih-Mao Chen <cmchen@andestech.com>
---
newlib/libc/machine/riscv/memcpy.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/newlib/libc/machine/riscv/memcpy.c
b/newlib/libc/machine/riscv/memcpy.c
index 07e8e0076..4098f3ab1 100644
--- a/newlib/libc/machine/riscv/memcpy.c
+++ b/newlib/libc/machine/riscv/memcpy.c
@@ -51,9 +51,9 @@ small:
const long *lb = (const long *)b;
long *lend = (long *)((uintptr_t)end & ~msk);
- if (unlikely (la < (lend - 8)))
+ if (unlikely (lend - la > 8))
{
- while (la < (lend - 8))
+ while (lend - la > 8)
{
long b0 = *lb++;
long b1 = *lb++;
--
2.27.0
next reply other threads:[~2020-07-24 11:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-24 11:07 PkmX [this message]
2020-07-27 8:15 ` Corinna Vinschen
2020-07-27 8:48 ` Kito Cheng
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='CACSh3m3euJOWd94oEpV6MWUUqm4Ehg3bt_x4y-HZTX0j=qZs7w@mail.gmail.com' \
--to=pkmx.tw@gmail.com \
--cc=newlib@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: link
Be 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).