diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-11 12:39:48 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-11 12:39:48 +0100 |
commit | 932b9971d05d26e353f56bdd93daec3c9f764312 (patch) | |
tree | 7c5683bbf957129eed25aa211a32bfcd9ce143ca | |
parent | aaf7a2e24d4c284328569eff44e67e29b223822b (diff) | |
download | busybox-w32-932b9971d05d26e353f56bdd93daec3c9f764312.tar.gz busybox-w32-932b9971d05d26e353f56bdd93daec3c9f764312.tar.bz2 busybox-w32-932b9971d05d26e353f56bdd93daec3c9f764312.zip |
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.right | 2 | ||||
-rwxr-xr-x | shell/ash_test/ash-misc/control_char1.tests | 2 | ||||
-rw-r--r-- | shell/hush.c | 23 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/control_char1.right | 2 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/control_char1.tests | 2 |
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 @@ | |||
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 @@ | |||
1 | echo | ||
2 | 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 @@ | |||
462 | # define MINUS_PLUS_EQUAL_QUESTION ("%#:-=+?" + 3) | 462 | # define MINUS_PLUS_EQUAL_QUESTION ("%#:-=+?" + 3) |
463 | #endif | 463 | #endif |
464 | 464 | ||
465 | #define SPECIAL_VAR_SYMBOL 3 | 465 | #define SPECIAL_VAR_SYMBOL_STR "\3" |
466 | #define SPECIAL_VAR_SYMBOL 3 | ||
467 | /* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */ | ||
468 | #define SPECIAL_VAR_QUOTED_SVS 1 | ||
466 | 469 | ||
467 | struct variable; | 470 | struct variable; |
468 | 471 | ||
@@ -4899,7 +4902,8 @@ static struct pipe *parse_stream(char **pstring, | |||
4899 | next = i_peek(input); | 4902 | next = i_peek(input); |
4900 | 4903 | ||
4901 | is_special = "{}<>;&|()#'" /* special outside of "str" */ | 4904 | is_special = "{}<>;&|()#'" /* special outside of "str" */ |
4902 | "\\$\"" IF_HUSH_TICK("`"); /* always special */ | 4905 | "\\$\"" IF_HUSH_TICK("`") /* always special */ |
4906 | SPECIAL_VAR_SYMBOL_STR; | ||
4903 | /* Are { and } special here? */ | 4907 | /* Are { and } special here? */ |
4904 | if (ctx.command->argv /* word [word]{... - non-special */ | 4908 | if (ctx.command->argv /* word [word]{... - non-special */ |
4905 | || dest.length /* word{... - non-special */ | 4909 | || dest.length /* word{... - non-special */ |
@@ -5171,8 +5175,14 @@ static struct pipe *parse_stream(char **pstring, | |||
5171 | /* Note: nommu_addchr(&ctx.as_string, ch) is already done */ | 5175 | /* Note: nommu_addchr(&ctx.as_string, ch) is already done */ |
5172 | 5176 | ||
5173 | switch (ch) { | 5177 | switch (ch) { |
5174 | case '#': /* non-comment #: "echo a#b" etc */ | 5178 | case SPECIAL_VAR_SYMBOL: |
5175 | o_addQchr(&dest, ch); | 5179 | /* Convert raw ^C to corresponding special variable reference */ |
5180 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); | ||
5181 | o_addchr(&dest, SPECIAL_VAR_QUOTED_SVS); | ||
5182 | /* fall through */ | ||
5183 | case '#': | ||
5184 | /* non-comment #: "echo a#b" etc */ | ||
5185 | o_addchr(&dest, ch); | ||
5176 | break; | 5186 | break; |
5177 | case '\\': | 5187 | case '\\': |
5178 | if (next == EOF) { | 5188 | if (next == EOF) { |
@@ -6026,6 +6036,11 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) | |||
6026 | arg++; | 6036 | arg++; |
6027 | cant_be_null = 0x80; | 6037 | cant_be_null = 0x80; |
6028 | break; | 6038 | break; |
6039 | case SPECIAL_VAR_QUOTED_SVS: | ||
6040 | /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */ | ||
6041 | arg++; | ||
6042 | val = SPECIAL_VAR_SYMBOL_STR; | ||
6043 | break; | ||
6029 | #if ENABLE_HUSH_TICK | 6044 | #if ENABLE_HUSH_TICK |
6030 | case '`': /* <SPECIAL_VAR_SYMBOL>`cmd<SPECIAL_VAR_SYMBOL> */ | 6045 | case '`': /* <SPECIAL_VAR_SYMBOL>`cmd<SPECIAL_VAR_SYMBOL> */ |
6031 | *p = '\0'; /* replace trailing <SPECIAL_VAR_SYMBOL> */ | 6046 | *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 @@ | |||
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 @@ | |||
1 | echo | ||
2 | echo Done:$? | ||