You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/03/23 20:10:29 UTC
[nuttx-apps] 03/04: nsh/nsh_parse.c: Fix variable expansion inside double quotes
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit ad18a50282eb3cf0d391bc5a457e73e576cdae99
Author: Ville Juven <vi...@unikie.com>
AuthorDate: Tue Mar 14 11:14:08 2023 +0200
nsh/nsh_parse.c: Fix variable expansion inside double quotes
This also prevents expanding anything when inside single quotes, for
full POSIX compliance.
---
nshlib/nsh_parse.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index f2cc78cd0..392d59eb3 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -1638,6 +1638,7 @@ static FAR char *nsh_argument(FAR struct nsh_vtbl_s *vtbl,
FAR char *prev;
bool escaped;
#endif
+ bool squote;
bool quoted;
/* Find the beginning of the next token */
@@ -1694,6 +1695,7 @@ static FAR char *nsh_argument(FAR struct nsh_vtbl_s *vtbl,
* make sure that we do not break up any quoted substrings.
*/
+ squote = false;
quoted = false;
#ifdef CONFIG_NSH_QUOTE
escaped = false;
@@ -1747,6 +1749,24 @@ static FAR char *nsh_argument(FAR struct nsh_vtbl_s *vtbl,
return NULL;
}
+ /* Is it a single-quote ? No expansion allowed */
+
+ if (*pend == '\'')
+ {
+ /* Yes, do not allow any expansions whatsoever */
+
+ squote = true;
+ }
+
+ /* Is it a double-quote ? Variable expansion is allowed */
+
+ if (*pend == '"')
+ {
+ /* Don't split env variable if inside double quotes */
+
+ isenvvar = NULL;
+ }
+
/* Is it a back-quote ? These are not removed here */
if (*pend != '`')
@@ -1797,7 +1817,14 @@ static FAR char *nsh_argument(FAR struct nsh_vtbl_s *vtbl,
/* Perform expansions as necessary for the argument */
- argument = nsh_argexpand(vtbl, pbegin, &allocation, isenvvar);
+ if (squote)
+ {
+ argument = pbegin;
+ }
+ else
+ {
+ argument = nsh_argexpand(vtbl, pbegin, &allocation, isenvvar);
+ }
}
/* If any memory was allocated for this argument, make sure that it is