qemu-trivial.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-trivial] [PATCH] readline: Fix buffer overrun on re-add to history
@ 2011-11-04 10:10 Markus Armbruster
  2011-11-07  8:04 ` [Qemu-trivial] [Qemu-devel] " Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2011-11-04 10:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial

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>
---
 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.6.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-trivial] [Qemu-devel] [PATCH] readline: Fix buffer overrun on re-add to history
  2011-11-04 10:10 [Qemu-trivial] [PATCH] readline: Fix buffer overrun on re-add to history Markus Armbruster
@ 2011-11-07  8:04 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2011-11-07  8:04 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-trivial, qemu-devel

On Fri, Nov 04, 2011 at 11:10:01AM +0100, Markus Armbruster wrote:
> 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>
> ---
>  readline.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches

Stefan


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-07  9:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-04 10:10 [Qemu-trivial] [PATCH] readline: Fix buffer overrun on re-add to history Markus Armbruster
2011-11-07  8:04 ` [Qemu-trivial] [Qemu-devel] " Stefan Hajnoczi

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).