[git commit] ash: expand: Fix bugs with words connected to the right of $@

Denys Vlasenko vda.linux at googlemail.com
Mon Apr 2 12:27:50 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=9a95df90463ee0eddc0585f0e5affa827701fdfb
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

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 at gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c                                    | 11 +++++++----
 shell/ash_test/ash-parsing/starquoted3.right   |  2 ++
 shell/ash_test/ash-parsing/starquoted3.tests   |  1 +
 shell/hush_test/hush-parsing/starquoted3.right |  2 ++
 shell/hush_test/hush-parsing/starquoted3.tests |  1 +
 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)
 		realifs = ifsset() ? ifsval() : defifs;
 		ifsp = &ifsfirst;
 		do {
+			int afternul;
+
 			p = string + ifsp->begoff;
+			afternul = nulonly;
 			nulonly = ifsp->nulonly;
 			ifs = nulonly ? nullstr : realifs;
 			ifsspc = 0;
@@ -5987,7 +5990,7 @@ ifsbreakup(char *string, struct arglist *arglist)
 					p++;
 					continue;
 				}
-				if (!nulonly)
+				if (!(afternul || nulonly))
 					ifsspc = (strchr(defifs, *p) != NULL);
 				/* Ignore IFS whitespace at start */
 				if (q == start && ifsspc) {
@@ -6650,12 +6653,12 @@ argstr(char *p, int flags)
 		case CTLENDVAR: /* ??? */
 			goto breakloop;
 		case CTLQUOTEMARK:
-			inquotes ^= EXP_QUOTED;
 			/* "$@" syntax adherence hack */
-			if (inquotes && !memcmp(p, dolatstr + 1, DOLATSTRLEN - 1)) {
-				p = evalvar(p + 1, flags | inquotes) + 1;
+			if (!inquotes && !memcmp(p, dolatstr + 1, DOLATSTRLEN - 1)) {
+				p = evalvar(p + 1, flags | EXP_QUOTED) + 1;
 				goto start;
 			}
+			inquotes ^= EXP_QUOTED;
  addquote:
 			if (flags & QUOTES_ESC) {
 				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 @@
+<a>
+<>
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 @@
+<a>
+<>
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


More information about the busybox-cvs mailing list