This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 7e03b989c nshlib/nsh_parse.c: do not run a command with too many
arguments.
7e03b989c is described below
commit 7e03b989c7be11b325d76cc030baef1ae536df0d
Author: raiden00pl <[email protected]>
AuthorDate: Sat Oct 10 18:06:20 2026 +0200
nshlib/nsh_parse.c: do not run a command with too many arguments.
nsh_parse_command() and nsh_parse_cmdparm() printed "too many
arguments" when argc exceeded CONFIG_NSH_MAXARGUMENTS but still ran
the command. The command then ran with all arguments, or, with more
than MAX_ARGV_ENTRIES - 1 words, with the words after that silently
dropped (they are not parsed).
Report the error and fail the command instead, as a shell does when
exec() fails with E2BIG. NSH commands already reject argc above their
maxargs in nsh_command(); this also covers builtin and file
applications.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: raiden00pl <[email protected]>
---
nshlib/nsh_parse.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index 371d2c40f..7cba9cc40 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -2450,11 +2450,16 @@ static int nsh_parse_cmdparm(FAR struct nsh_vtbl_s
*vtbl, FAR char *cmdline,
argv[argc] = NULL;
- /* Check if the maximum number of arguments was exceeded */
+ /* Check if the maximum number of arguments was exceeded. Do not run
+ * the command then: words past MAX_ARGV_ENTRIES were not parsed, so its
+ * argument list may be truncated.
+ */
if (argc > CONFIG_NSH_MAXARGUMENTS)
{
nsh_error(vtbl, g_fmttoomanyargs, cmd);
+ ret = nsh_saveresult(vtbl, true);
+ goto exit;
}
/* Then execute the command */
@@ -2904,11 +2909,16 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s
*vtbl, FAR char *cmdline)
argv[argc] = NULL;
- /* Check if the maximum number of arguments was exceeded */
+ /* Check if the maximum number of arguments was exceeded. Do not run
+ * the command then: words past MAX_ARGV_ENTRIES were not parsed, so its
+ * argument list may be truncated.
+ */
if (argc > CONFIG_NSH_MAXARGUMENTS)
{
nsh_error(vtbl, g_fmttoomanyargs, cmd);
+ ret = nsh_saveresult(vtbl, true);
+ goto dynlist_free;
}
/* Then execute the command */