aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-11 12:39:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-11 12:39:48 +0100
commit932b9971d05d26e353f56bdd93daec3c9f764312 (patch)
tree7c5683bbf957129eed25aa211a32bfcd9ce143ca
parentaaf7a2e24d4c284328569eff44e67e29b223822b (diff)
downloadbusybox-932b9971d05d26e353f56bdd93daec3c9f764312.tar.gz
hush: fix handling of raw ^C in scripts: "echo ^C"
function old new delta expand_vars_to_list 1133 1187 +54 parse_stream 2690 2719 +29 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash_test/ash-misc/control_char1.right2
-rwxr-xr-xshell/ash_test/ash-misc/control_char1.tests2
-rw-r--r--shell/hush.c23
-rw-r--r--shell/hush_test/hush-misc/control_char1.right2
-rwxr-xr-xshell/hush_test/hush-misc/control_char1.tests2
5 files changed, 27 insertions, 4 deletions
diff --git a/shell/ash_test/ash-misc/control_char1.right b/shell/ash_test/ash-misc/control_char1.right
new file mode 100644
index 000000000..9498b420d
--- /dev/null
+++ b/shell/ash_test/ash-misc/control_char1.right
@@ -0,0 +1,2 @@
+
+Done:0
diff --git a/shell/ash_test/ash-misc/control_char1.tests b/shell/ash_test/ash-misc/control_char1.tests
new file mode 100755
index 000000000..a2ebeba1b
--- /dev/null
+++ b/shell/ash_test/ash-misc/control_char1.tests
@@ -0,0 +1,2 @@
+echo 
+echo Done:$?
diff --git a/shell/hush.c b/shell/hush.c
index 6c47be885..48f503cb6 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -462,7 +462,10 @@
# define MINUS_PLUS_EQUAL_QUESTION ("%#:-=+?" + 3)
#endif
-#define SPECIAL_VAR_SYMBOL 3
+#define SPECIAL_VAR_SYMBOL_STR "\3"
+#define SPECIAL_VAR_SYMBOL 3
+/* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */
+#define SPECIAL_VAR_QUOTED_SVS 1
struct variable;
@@ -4899,7 +4902,8 @@ static struct pipe *parse_stream(char **pstring,
next = i_peek(input);
is_special = "{}<>;&|()#'" /* special outside of "str" */
- "\\$\"" IF_HUSH_TICK("`"); /* always special */
+ "\\$\"" IF_HUSH_TICK("`") /* always special */
+ SPECIAL_VAR_SYMBOL_STR;
/* Are { and } special here? */
if (ctx.command->argv /* word [word]{... - non-special */
|| dest.length /* word{... - non-special */
@@ -5171,8 +5175,14 @@ static struct pipe *parse_stream(char **pstring,
/* Note: nommu_addchr(&ctx.as_string, ch) is already done */
switch (ch) {
- case '#': /* non-comment #: "echo a#b" etc */
- o_addQchr(&dest, ch);
+ case SPECIAL_VAR_SYMBOL:
+ /* Convert raw ^C to corresponding special variable reference */
+ o_addchr(&dest, SPECIAL_VAR_SYMBOL);
+ o_addchr(&dest, SPECIAL_VAR_QUOTED_SVS);
+ /* fall through */
+ case '#':
+ /* non-comment #: "echo a#b" etc */
+ o_addchr(&dest, ch);
break;
case '\\':
if (next == EOF) {
@@ -6026,6 +6036,11 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
arg++;
cant_be_null = 0x80;
break;
+ case SPECIAL_VAR_QUOTED_SVS:
+ /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */
+ arg++;
+ val = SPECIAL_VAR_SYMBOL_STR;
+ break;
#if ENABLE_HUSH_TICK
case '`': /* <SPECIAL_VAR_SYMBOL>`cmd<SPECIAL_VAR_SYMBOL> */
*p = '\0'; /* replace trailing <SPECIAL_VAR_SYMBOL> */
diff --git a/shell/hush_test/hush-misc/control_char1.right b/shell/hush_test/hush-misc/control_char1.right
new file mode 100644
index 000000000..9498b420d
--- /dev/null
+++ b/shell/hush_test/hush-misc/control_char1.right
@@ -0,0 +1,2 @@
+
+Done:0
diff --git a/shell/hush_test/hush-misc/control_char1.tests b/shell/hush_test/hush-misc/control_char1.tests
new file mode 100755
index 000000000..a2ebeba1b
--- /dev/null
+++ b/shell/hush_test/hush-misc/control_char1.tests
@@ -0,0 +1,2 @@
+echo 
+echo Done:$?