xiaoxiang781216 commented on code in PR #2850:
URL: https://github.com/apache/nuttx-apps/pull/2850#discussion_r1840682853
##########
nshlib/nsh_parse.c:
##########
@@ -603,24 +603,31 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
FAR char *sh_argv[4];
FAR char *sh_cmd = "sh";
- int i;
+ char cmd_str[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++)
+ memset(cmd_str, 0, sizeof(cmd_str));
Review Comment:
`cmd_str[0] = '\0';`
##########
nshlib/nsh_parse.c:
##########
@@ -603,24 +603,31 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
FAR char *sh_argv[4];
FAR char *sh_cmd = "sh";
- int i;
+ char cmd_str[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++)
+ memset(cmd_str, 0, sizeof(cmd_str));
+
+ for (ret = 0; ret < argc; ret++)
{
- FAR char *p_arg = argv[i];
- size_t len = strlen(p_arg);
+ if (sizeof(cmd_str) - strlen(cmd_str) - 1 <
Review Comment:
let's skip the check since it's impossible to larger than CONFIG_NSH_LINELEN
##########
nshlib/nsh_parse.c:
##########
@@ -603,24 +603,31 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
FAR char *sh_argv[4];
FAR char *sh_cmd = "sh";
- int i;
+ char cmd_str[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++)
+ memset(cmd_str, 0, sizeof(cmd_str));
+
+ for (ret = 0; ret < argc; ret++)
{
- FAR char *p_arg = argv[i];
- size_t len = strlen(p_arg);
+ if (sizeof(cmd_str) - strlen(cmd_str) - 1 <
+ strlen(argv[ret]) + 1)
+ {
+ return nsh_saveresult(vtbl, true);
+ }
- /* Restore from split args to concat args. */
+ strcat(cmd_str, argv[ret]);
Review Comment:
strlcat
##########
nshlib/nsh_parse.c:
##########
@@ -603,24 +603,31 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
FAR char *sh_argv[4];
FAR char *sh_cmd = "sh";
- int i;
+ char cmd_str[CONFIG_NSH_LINELEN];
Review Comment:
```suggestion
char sh_arg2[CONFIG_NSH_LINELEN];
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]