From patchwork Fri Jan 11 09:18:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1/6] readline: avoid memcpy() of overlapping regions X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 211263 Message-Id: <1357895886-14283-2-git-send-email-stefanha@redhat.com> To: Cc: Anthony Liguori , Nickolai Zeldovich , Stefan Hajnoczi Date: Fri, 11 Jan 2013 10:18:01 +0100 From: Stefan Hajnoczi List-Id: From: Nickolai Zeldovich memcpy() for overlapping regions is undefined behavior; use memmove() instead in readline_hist_add(). [Keep tab characters since surrounding code still uses them -- Stefan] Signed-off-by: Nickolai Zeldovich Reviewed-by: Richard Henderson Signed-off-by: Stefan Hajnoczi --- readline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readline.c b/readline.c index 5fc9643..a0c9638 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; }