Skip to contentSkip to conversation

hush shell: Avoid string write overflow when entering max cmd length

PATCH In review Kristian Otnes 2 participants 2 messages Apr 25, 2014 – May 13, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hush shell: Avoid string write overflow when entering max cmd length

console_buffer array is defined to be CONFIG_SYS_CBSIZE + 1 long, whereas the_command array only CONFIG_SYS_CBSIZE long. Subsequent use of strcpy(the_command, console_buffer) will write final \0 terminating byte outside the_command array when entering a command of max length.

Signed-off-by Kristian Otnes <kotnes <at> cisco <dot> com>
---
 common/hush.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/hush.c +1 -1
index df10267..5b43224 100644
@@ -996,7 +996,7 @@ static void get_user_input(struct in_str *i)
 	i->p = the_command;
 #else
 	int n;
-	static char the_command[CONFIG_SYS_CBSIZE];
+	static char the_command[CONFIG_SYS_CBSIZE + 1];
 
 #ifdef CONFIG_BOOT_RETRY_TIME
 #  ifndef CONFIG_RESET_TO_RETRY
Signature · 1 line
1.7.10.1
#1 lore raw
Quoted 7 lines · Kristian Otnes

console_buffer array is defined to be CONFIG_SYS_CBSIZE + 1 long, whereas the_command array only CONFIG_SYS_CBSIZE long. Subsequent use of strcpy(the_command, console_buffer) will write final \0 terminating byte outside the_command array when entering a command of max length.

Signed-off-by Kristian Otnes <kotnes <at> cisco <dot> com>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140512/1b04ce4f/attachment.pgp>