aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-02 14:27:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-02 14:27:50 +0200
commit9a95df90463ee0eddc0585f0e5affa827701fdfb (patch)
tree38e0902751c50c55ad874499b4d4be6e7f53b45c
parent355ec353be14f33f69fe3e3992ab5a815b3a01a6 (diff)
downloadbusybox-w32-9a95df90463ee0eddc0585f0e5affa827701fdfb.tar.gz
busybox-w32-9a95df90463ee0eddc0585f0e5affa827701fdfb.tar.bz2
busybox-w32-9a95df90463ee0eddc0585f0e5affa827701fdfb.zip
ash: expand: Fix bugs with words connected to the right of $@
Upstream email: This is actually composed of two bugs. First of all our tracking of quotemark is wrong so anything after "$@" becomes quoted. Once we fix that then the problem is that the first space character after "$@" is not recognised as an IFS. This patch fixes both. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c11
-rw-r--r--shell/ash_test/ash-parsing/starquoted3.right2
-rwxr-xr-xshell/ash_test/ash-parsing/starquoted3.tests1
-rw-r--r--shell/hush_test/hush-parsing/starquoted3.right2
-rwxr-xr-xshell/hush_test/hush-parsing/starquoted3.tests1
5 files changed, 13 insertions, 4 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 35ea58f3a..d82eba15f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5975,7 +5975,10 @@ ifsbreakup(char *string, struct arglist *arglist)
5975 realifs = ifsset() ? ifsval() : defifs; 5975 realifs = ifsset() ? ifsval() : defifs;
5976 ifsp = &ifsfirst; 5976 ifsp = &ifsfirst;
5977 do { 5977 do {
5978 int afternul;
5979
5978 p = string + ifsp->begoff; 5980 p = string + ifsp->begoff;
5981 afternul = nulonly;
5979 nulonly = ifsp->nulonly; 5982 nulonly = ifsp->nulonly;
5980 ifs = nulonly ? nullstr : realifs; 5983 ifs = nulonly ? nullstr : realifs;
5981 ifsspc = 0; 5984 ifsspc = 0;
@@ -5987,7 +5990,7 @@ ifsbreakup(char *string, struct arglist *arglist)
5987 p++; 5990 p++;
5988 continue; 5991 continue;
5989 } 5992 }
5990 if (!nulonly) 5993 if (!(afternul || nulonly))
5991 ifsspc = (strchr(defifs, *p) != NULL); 5994 ifsspc = (strchr(defifs, *p) != NULL);
5992 /* Ignore IFS whitespace at start */ 5995 /* Ignore IFS whitespace at start */
5993 if (q == start && ifsspc) { 5996 if (q == start && ifsspc) {
@@ -6650,12 +6653,12 @@ argstr(char *p, int flags)
6650 case CTLENDVAR: /* ??? */ 6653 case CTLENDVAR: /* ??? */
6651 goto breakloop; 6654 goto breakloop;
6652 case CTLQUOTEMARK: 6655 case CTLQUOTEMARK:
6653 inquotes ^= EXP_QUOTED;
6654 /* "$@" syntax adherence hack */ 6656 /* "$@" syntax adherence hack */
6655 if (inquotes && !memcmp(p, dolatstr + 1, DOLATSTRLEN - 1)) { 6657 if (!inquotes && !memcmp(p, dolatstr + 1, DOLATSTRLEN - 1)) {
6656 p = evalvar(p + 1, flags | inquotes) + 1; 6658 p = evalvar(p + 1, flags | EXP_QUOTED) + 1;
6657 goto start; 6659 goto start;
6658 } 6660 }
6661 inquotes ^= EXP_QUOTED;
6659 addquote: 6662 addquote:
6660 if (flags & QUOTES_ESC) { 6663 if (flags & QUOTES_ESC) {
6661 p--; 6664 p--;
diff --git a/shell/ash_test/ash-parsing/starquoted3.right b/shell/ash_test/ash-parsing/starquoted3.right
new file mode 100644
index 000000000..fea246c14
--- /dev/null
+++ b/shell/ash_test/ash-parsing/starquoted3.right
@@ -0,0 +1,2 @@
1<a>
2<>
diff --git a/shell/ash_test/ash-parsing/starquoted3.tests b/shell/ash_test/ash-parsing/starquoted3.tests
new file mode 100755
index 000000000..8eefe4245
--- /dev/null
+++ b/shell/ash_test/ash-parsing/starquoted3.tests
@@ -0,0 +1 @@
set -- a ""; space=" "; printf "<%s>\n" "$@"$space
diff --git a/shell/hush_test/hush-parsing/starquoted3.right b/shell/hush_test/hush-parsing/starquoted3.right
new file mode 100644
index 000000000..fea246c14
--- /dev/null
+++ b/shell/hush_test/hush-parsing/starquoted3.right
@@ -0,0 +1,2 @@
1<a>
2<>
diff --git a/shell/hush_test/hush-parsing/starquoted3.tests b/shell/hush_test/hush-parsing/starquoted3.tests
new file mode 100755
index 000000000..8eefe4245
--- /dev/null
+++ b/shell/hush_test/hush-parsing/starquoted3.tests
@@ -0,0 +1 @@
set -- a ""; space=" "; printf "<%s>\n" "$@"$space