From 6475b9f91bd33bfd38418469cabdcfc0fefbd848 Mon Sep 17 00:00:00 2001 From: John Schmoller Date: Fri, 12 Mar 2010 09:49:23 -0600 Subject: console: Fix console buffer overrun When CONFIG_SYS_CBSIZE equals MAX_CMDBUF_SIZE, a command string of maximum length will overwrite part of the history buffer, causing the board to die. Expand the console_buffer and hist_lines buffer by one character each to hold the missing NULL char. Signed-off-by: John Schmoller --- common/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common/main.c') diff --git a/common/main.c b/common/main.c index c860b0b..6fec200 100644 --- a/common/main.c +++ b/common/main.c @@ -68,7 +68,7 @@ static int abortboot(int); #undef DEBUG_PARSER -char console_buffer[CONFIG_SYS_CBSIZE]; /* console I/O buffer */ +char console_buffer[CONFIG_SYS_CBSIZE + 1]; /* console I/O buffer */ static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen); static char erase_seq[] = "\b \b"; /* erase sequence */ @@ -546,7 +546,7 @@ static int hist_cur = -1; unsigned hist_num = 0; char* hist_list[HIST_MAX]; -char hist_lines[HIST_MAX][HIST_SIZE]; +char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */ #define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1) -- cgit v1.1 From d611295032c30e6c533cb356005fa82ab7992824 Mon Sep 17 00:00:00 2001 From: John Schmoller Date: Fri, 12 Mar 2010 09:49:24 -0600 Subject: cmd history: Match history buffer size to console buffer Match history buffer size to console buffer size. History buffer size was hard coded to 256, artificially limiting the command buffer size. The history buffer now tracks CONFIG_SYS_CBSIZE. Signed-off-by: John Schmoller --- common/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/main.c') diff --git a/common/main.c b/common/main.c index 6fec200..3949a5b 100644 --- a/common/main.c +++ b/common/main.c @@ -526,7 +526,7 @@ void reset_cmd_timeout(void) #define CTL_CH(c) ((c) - 'a' + 1) -#define MAX_CMDBUF_SIZE 256 +#define MAX_CMDBUF_SIZE CONFIG_SYS_CBSIZE #define CTL_BACKSPACE ('\b') #define DEL ((char)255) -- cgit v1.1