Skip to content

Commit 12d3107

Browse files
no1wudipkarashchenko
authored andcommitted
nsh: Fix a buffer overflow in help
Introduced by #1610, internal line buffer should have more bytes for tab before newline and '\0'. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
1 parent 509e90a commit 12d3107

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nshlib/nsh_command.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
/* Help command summary layout */
4646

4747
#define HELP_LINELEN 80
48+
#define HELP_TABSIZE 4
4849
#define NUM_CMDS ((sizeof(g_cmdmap)/sizeof(struct cmdmap_s)) - 1)
4950

5051
/****************************************************************************
@@ -616,7 +617,10 @@ static inline void help_cmdlist(FAR struct nsh_vtbl_s *vtbl)
616617
unsigned int j;
617618
unsigned int k;
618619
unsigned int offset;
619-
char line[HELP_LINELEN];
620+
621+
/* Extra 5 bytes for tab before newline and '\0' */
622+
623+
char line[HELP_LINELEN + HELP_TABSIZE + 1];
620624

621625
/* Pick an optimal column width */
622626

@@ -654,7 +658,7 @@ static inline void help_cmdlist(FAR struct nsh_vtbl_s *vtbl)
654658
{
655659
/* Tab before a new line */
656660

657-
offset = 4;
661+
offset = HELP_TABSIZE;
658662
memset(line, ' ', offset);
659663

660664
for (j = 0, k = i;

0 commit comments

Comments
 (0)