From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Markus Armbruster <armbru@redhat.com>,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 4/5] readline: Fix buffer overrun on re-add to history
Date: Mon, 7 Nov 2011 09:26:59 +0000 [thread overview]
Message-ID: <1320658020-4374-5-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1320658020-4374-1-git-send-email-stefanha@linux.vnet.ibm.com>
From: Markus Armbruster <armbru@redhat.com>
readline_hist_add() moves the history entry to the end of history. It
uses memmove() to move rs->history[idx + 1..] to rs->history[idx..].
However, its size argument is off by two array elements, so it writes
one element beyond rs->history[], and reads two.
On my system, this clobbers rs->hist_entry and the hole right after
it. Since the function assigns to rs->hist_entry in time, the bug has
no ill effects for me.
Spotted by Coverity.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
readline.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/readline.c b/readline.c
index 6a3160a..a6c0039 100644
--- a/readline.c
+++ b/readline.c
@@ -236,7 +236,7 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
new_entry = hist_entry;
/* Put this entry at the end of history */
memmove(&rs->history[idx], &rs->history[idx + 1],
- (READLINE_MAX_CMDS - idx + 1) * sizeof(char *));
+ (READLINE_MAX_CMDS - (idx + 1)) * sizeof(char *));
rs->history[READLINE_MAX_CMDS - 1] = NULL;
for (; idx < READLINE_MAX_CMDS; idx++) {
if (rs->history[idx] == NULL)
--
1.7.7.1
next prev parent reply other threads:[~2011-11-07 9:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-07 9:26 [Qemu-devel] [PULL 0/5] Trivial patches for 2 to 7 November 2011 Stefan Hajnoczi
2011-11-07 9:26 ` [Qemu-devel] [PATCH 1/5] cmd: Fix coding style in cmd.c Stefan Hajnoczi
2011-11-07 9:26 ` [Qemu-devel] [PATCH 2/5] cmd: Fix potential NULL pointer dereference Stefan Hajnoczi
2011-11-07 9:26 ` [Qemu-devel] [PATCH 3/5] cmd: Fix potential memory leak Stefan Hajnoczi
2011-11-07 9:26 ` Stefan Hajnoczi [this message]
2011-11-07 9:27 ` [Qemu-devel] [PATCH 5/5] xen-platform: Fix IO port read/write functions Stefan Hajnoczi
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=1320658020-4374-5-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--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).