You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/01/01 14:18:14 UTC
[incubator-nuttx-apps] branch master updated (6993c66 -> 6285990)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git.
from 6993c66 Check for too many arguments to hostname
new 92287e2 Fix some edge case bugs in nsh_parse
new 6285990 Remove trailing whitespace from commands as parameters
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
nshlib/nsh_parse.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
[incubator-nuttx-apps] 01/02: Fix some edge case bugs in nsh_parse
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 92287e2b148e4861278cb1489bdc19a321c4614b
Author: Norman Rasmussen <no...@rasmussen.co.za>
AuthorDate: Fri Dec 31 06:54:57 2021 -0800
Fix some edge case bugs in nsh_parse
- Handle nsh_filecat returning NULL on failure
- Background and redirect must be restored after an empty line
- Output redirection should be removed from argv like background
---
nshlib/nsh_parse.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index 8b51181..bca4c6c 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -943,8 +943,15 @@ static FAR char *nsh_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
/* Concatenate the file contents with the current allocation */
- argument = nsh_filecat(vtbl, *allocation, tmpfile);
- *allocation = argument;
+ argument = nsh_filecat(vtbl, *allocation, tmpfile);
+ if (argument == NULL)
+ {
+ argument = (FAR char *)g_nullstring;
+ }
+ else
+ {
+ *allocation = argument;
+ }
/* We can now unlink the tmpfile and free the tmpfile string */
@@ -2305,8 +2312,8 @@ static int nsh_parse_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
* status.
*/
- NSH_MEMLIST_FREE(&memlist);
- return OK;
+ ret = 0;
+ goto exit;
}
/* Parse all of the arguments following the command name. The form
@@ -2346,6 +2353,7 @@ static int nsh_parse_cmdparm(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
/* Restore the backgrounding and redirection state */
+exit:
#ifndef CONFIG_NSH_DISABLEBG
vtbl->np.np_bg = bgsave;
#endif
@@ -2522,17 +2530,12 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
}
}
- /* Last argument vector must be empty */
-
- argv[argc] = NULL;
-
/* Check if the command should run in background */
#ifndef CONFIG_NSH_DISABLEBG
if (argc > 1 && strcmp(argv[argc - 1], "&") == 0)
{
vtbl->np.np_bg = true;
- argv[argc - 1] = NULL;
argc--;
}
#endif
@@ -2566,6 +2569,10 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
}
#endif
+ /* Last argument vector must be empty */
+
+ argv[argc] = NULL;
+
/* Check if the maximum number of arguments was exceeded */
if (argc > CONFIG_NSH_MAXARGUMENTS)
[incubator-nuttx-apps] 02/02: Remove trailing whitespace from commands as parameters
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 6285990a5c4fe01accce6daef0f7dd3f12c1203c
Author: Norman Rasmussen <no...@rasmussen.co.za>
AuthorDate: Fri Dec 31 06:02:26 2021 -0800
Remove trailing whitespace from commands as parameters
---
nshlib/nsh_parse.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index bca4c6c..c15115e 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -829,7 +829,7 @@ static FAR char *nsh_filecat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
fd = open(filename, O_RDONLY);
if (fd < 0)
{
- nsh_error(vtbl, g_fmtcmdfailed, "``", "open", NSH_ERRNO);
+ nsh_error(vtbl, g_fmtcmdfailed, "``", "open", NSH_ERRNO);
goto errout_with_alloc;
}
@@ -877,6 +877,13 @@ static FAR char *nsh_filecat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
index += nbytesread;
}
+ /* Remove trailing whitespace */
+
+ for (;
+ index > s1size &&
+ strchr(g_token_separator, argument[index - 1]) != NULL;
+ index--);
+
/* Make sure that the new string is null terminated */
argument[index] = '\0';