From dbf7d34a2af383da0e3b24e58c2834f9f2d87e37 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Wed, 8 Mar 2023 20:56:16 +0800 Subject: [PATCH] nsh: Fix a potential buffer overflow in cmd help Follow https://github.com/apache/nuttx-apps/pull/1621, fix issue of builtin command list. Signed-off-by: Huang Qi --- nshlib/nsh_command.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index f4f9c656b..e5ff25289 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -813,7 +813,11 @@ static inline void help_builtins(FAR struct nsh_vtbl_s *vtbl) unsigned int j; unsigned int k; unsigned int offset; - char line[HELP_LINELEN]; + + /* Extra 5 bytes for tab before newline and '\0' */ + + char line[HELP_LINELEN + HELP_TABSIZE + 1]; + static const char *g_builtin_prompt = "\nBuiltin Apps:\n"; /* Count the number of built-in commands and get the optimal column width */