qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Nickolai Zeldovich <nickolai@csail.mit.edu>
To: qemu-devel@nongnu.org
Cc: Nickolai Zeldovich <nickolai@csail.mit.edu>
Subject: [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions
Date: Mon,  7 Jan 2013 15:38:39 -0500	[thread overview]
Message-ID: <1357591119-40326-1-git-send-email-nickolai@csail.mit.edu> (raw)

memcpy() for overlapping regions is undefined behavior; use memmove()
instead in readline_hist_add().

Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
---
 readline.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/readline.c b/readline.c
index 5fc9643..aeccc7b 100644
--- a/readline.c
+++ b/readline.c
@@ -248,8 +248,8 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
     if (idx == READLINE_MAX_CMDS) {
 	/* Need to get one free slot */
 	free(rs->history[0]);
-	memcpy(rs->history, &rs->history[1],
-	       (READLINE_MAX_CMDS - 1) * sizeof(char *));
+        memmove(rs->history, &rs->history[1],
+                (READLINE_MAX_CMDS - 1) * sizeof(char *));
 	rs->history[READLINE_MAX_CMDS - 1] = NULL;
 	idx = READLINE_MAX_CMDS - 1;
     }
-- 
1.7.10.4

             reply	other threads:[~2013-01-07 20:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-07 20:38 Nickolai Zeldovich [this message]
2013-01-07 21:36 ` [Qemu-devel] [PATCH] readline: avoid memcpy() of overlapping regions Richard Henderson
2013-01-08  9:03 ` Stefan Hajnoczi
2013-01-09 20:43   ` Blue Swirl
2013-01-10 12:43     ` Stefan Hajnoczi
2013-01-12 10:46       ` Blue Swirl
2013-01-14  9:09         ` Stefan Hajnoczi
2013-01-17 20:13           ` Blue Swirl
2013-01-18 11:04             ` Stefan Hajnoczi
2013-01-19  9:04               ` Blue Swirl

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=1357591119-40326-1-git-send-email-nickolai@csail.mit.edu \
    --to=nickolai@csail.mit.edu \
    --cc=qemu-devel@nongnu.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 NNTP newsgroup(s).