aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorGravatar Ron Yorston <rmy@pobox.com>2015-05-18 09:53:26 +0200
committerGravatar Denys Vlasenko <vda.linux@googlemail.com>2015-05-18 09:53:26 +0200
commit3df47f9cbbb7f16608cbc642026625cdf7f06aa9 (patch)
treea2bc999e17bcf10c29bceeb1403cbc7ef658aa84 /shell
parenteb6b48ba743d510ad9e6f9c3a8b3899d1eb9b5f3 (diff)
downloadbusybox-3df47f9cbbb7f16608cbc642026625cdf7f06aa9.tar.gz
busybox-3df47f9cbbb7f16608cbc642026625cdf7f06aa9.tar.bz2
ash: do not expand tilde in parameter expansion within quotes
Test case: unset a echo "${a:-~root}" Old result: /root New result: ~root Based on commit 170f44d from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu function old new delta evalvar 598 604 +6 parse_command 1440 1443 +3 localcmd 325 327 +2 readtoken1 3199 3200 +1 argstr 1180 1164 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 12/-16) Total: -4 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c8
-rw-r--r--shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.right1
-rwxr-xr-xshell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.tests2
3 files changed, 6 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 4c43f1f30..d87166c4f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5529,7 +5529,7 @@ ash_arith(const char *s)
#define EXP_RECORD 0x20 /* need to record arguments for ifs breakup */
#define EXP_VARTILDE2 0x40 /* expand tildes after colons only */
#define EXP_WORD 0x80 /* expand word in parameter expansion */
-#define EXP_QWORD 0x100 /* expand word in quoted parameter expansion */
+#define EXP_QUOTED 0x100 /* expand word in double quotes */
/*
* rmescape() flags
*/
@@ -6054,7 +6054,7 @@ argstr(char *p, int flags, struct strlist *var_str_list)
};
const char *reject = spclchars;
int quotes = flags & QUOTES_ESC;
- int breakall = flags & EXP_WORD;
+ int breakall = (flags & (EXP_WORD | EXP_QUOTED)) == EXP_WORD;
int inquotes;
size_t length;
int startloc;
@@ -6072,8 +6072,6 @@ argstr(char *p, int flags, struct strlist *var_str_list)
flags &= ~EXP_TILDE;
tilde:
q = p;
- if ((unsigned char)*q == CTLESC && (flags & EXP_QWORD))
- q++;
if (*q == '~')
p = exptilde(p, q, flags);
}
@@ -6790,7 +6788,7 @@ evalvar(char *p, int flags, struct strlist *var_str_list)
if (varlen < 0) {
argstr(
p,
- flags | (quoted ? EXP_TILDE|EXP_QWORD : EXP_TILDE|EXP_WORD),
+ flags | EXP_TILDE | EXP_WORD | (quoted ? EXP_QUOTED : 0),
var_str_list
);
goto end;
diff --git a/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.right b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.right
new file mode 100644
index 000000000..4b9b4f038
--- /dev/null
+++ b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.right
@@ -0,0 +1 @@
+~root
diff --git a/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.tests b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.tests
new file mode 100755
index 000000000..d8eb8fc1b
--- /dev/null
+++ b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.tests
@@ -0,0 +1,2 @@
+unset a
+echo "${a:-~root}"