Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nshlib/nsh_parse: Fix variable arguments concat error of nsh_execute() #51

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions nshlib/nsh_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,24 +603,25 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
FAR char *sh_argv[4];
FAR char *sh_cmd = "sh";
int i;
char sh_arg2[CONFIG_NSH_LINELEN];

DEBUGASSERT(strncmp(argv[0], sh_cmd, 3) != 0);

sh_argv[0] = sh_cmd;
sh_argv[1] = "-c";
for (i = 0; i < argc - 1; i++)
{
FAR char *p_arg = argv[i];
size_t len = strlen(p_arg);
sh_arg2[0] = '\0';

/* Restore from split args to concat args. */
for (ret = 0; ret < argc; ret++)
{
strlcat(sh_arg2, argv[ret], sizeof(sh_arg2));

DEBUGASSERT(&p_arg[len + 1] == argv[i + 1]);
p_arg[len] = ' ';
if (ret < argc - 1)
{
strcat(sh_arg2, " ");
}
}

sh_argv[2] = argv[0];
sh_argv[0] = sh_cmd;
sh_argv[1] = "-c";
sh_argv[2] = sh_arg2;
sh_argv[3] = NULL;

/* np.np_bg still there, try use nsh_builtin or nsh_fileapp to
Expand Down
Loading