All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] readline: Fix possible array index out of bounds in readline_hist_add()
@ 2020-12-03 13:50 Alex Chen
  2020-12-17  9:47 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Chen @ 2020-12-03 13:50 UTC (permalink / raw)
  To: stefanha, mjt; +Cc: alex.chen, qemu-trivial, qemu-devel, zhang.zhanghailiang

When the 'cmdline' is the last entry in 'rs->history' array, there is
no need to put this entry to the end of the array, partly because it is
the last entry, and partly because the next operition will lead to array
index out of bounds.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Alex Chen <alex.chen@huawei.com>
---
 util/readline.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/util/readline.c b/util/readline.c
index e534460da6..f1ac6e4769 100644
--- a/util/readline.c
+++ b/util/readline.c
@@ -240,6 +240,9 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
         }
         if (strcmp(hist_entry, cmdline) == 0) {
         same_entry:
+            if (idx == READLINE_MAX_CMDS - 1) {
+                return;
+            }
             new_entry = hist_entry;
             /* Put this entry at the end of history */
             memmove(&rs->history[idx], &rs->history[idx + 1],
-- 
2.19.1



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

* Re: [PATCH] readline: Fix possible array index out of bounds in readline_hist_add()
  2020-12-03 13:50 [PATCH] readline: Fix possible array index out of bounds in readline_hist_add() Alex Chen
@ 2020-12-17  9:47 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2020-12-17  9:47 UTC (permalink / raw)
  To: Alex Chen; +Cc: qemu-trivial, mjt, qemu-devel, zhang.zhanghailiang

[-- Attachment #1: Type: text/plain, Size: 582 bytes --]

On Thu, Dec 03, 2020 at 01:50:43PM +0000, Alex Chen wrote:
> When the 'cmdline' is the last entry in 'rs->history' array, there is
> no need to put this entry to the end of the array, partly because it is
> the last entry, and partly because the next operition will lead to array
> index out of bounds.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Alex Chen <alex.chen@huawei.com>
> ---
>  util/readline.c | 3 +++
>  1 file changed, 3 insertions(+)

Thanks, applied to my block tree:
https://gitlab.com/stefanha/qemu/commits/block

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2020-12-17 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 13:50 [PATCH] readline: Fix possible array index out of bounds in readline_hist_add() Alex Chen
2020-12-17  9:47 ` Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.