Skip to contentSkip to conversation

readline: Fix possible array index out of bounds in readline_hist_add()

PATCH Applied Alex Chen 2 participants 2 messages Dec 3, 2020 – Dec 17, 2020

lore
Share & tools
lore

Alex Chen

author
#0 lore raw

PATCH 1/1 readline: Fix possible array index out of bounds in readline_hist_add()

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.

---
 util/readline.c | 3 +++
 1 file changed, 3 insertions(+)
util/readline.c +3 -0
index e534460da6..f1ac6e4769 100644
@@ -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],
Signature · 1 line
2.19.1
#1 lore raw
Quoted 10 lines · Alex Chen

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.

---
 util/readline.c | 3 +++
 1 file changed, 3 insertions(+)

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

Stefan