From: Andrew Cooper Subject: [PATCH 17/32] readline: fix memory corruption when adding history Date: Wed, 22 Apr 2015 16:07:54 +0100 Message-ID: <1429715289-4954-17-git-send-email-andrew.cooper3@citrix.com> References: <1429715235-4759-1-git-send-email-andrew.cooper3@citrix.com> <1429715289-4954-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1429715289-4954-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel List-Id: xen-devel@lists.xenproject.org From: Kaifeng Zhu idx can be down to 0, so TERM_MAX_CMDS-idx+1 could be TERM_MAX_CMDS+1, which exceeds the size of term_history. Signed-off-by: Kaifeng Zhu Coverity-ID: 1055739 Reviewed-by: Andrew Cooper --- readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readline.c b/readline.c index 8572841..4b68726 100644 --- a/readline.c +++ b/readline.c @@ -267,7 +267,7 @@ static void term_hist_add(const char *cmdline) new_entry = hist_entry; /* Put this entry at the end of history */ memmove(&term_history[idx], &term_history[idx + 1], - (TERM_MAX_CMDS - idx + 1) * sizeof(char *)); + (TERM_MAX_CMDS - (idx + 1)) * sizeof(char *)); term_history[TERM_MAX_CMDS - 1] = NULL; for (; idx < TERM_MAX_CMDS; idx++) { if (term_history[idx] == NULL) -- 1.7.10.4