aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/hush.c48
-rw-r--r--shell/hush_test/hush-misc/heredoc_backslash1.right8
-rwxr-xr-xshell/hush_test/hush-misc/heredoc_backslash1.tests8
-rw-r--r--shell/hush_test/hush-psubst/tick3.right2
-rwxr-xr-xshell/hush_test/hush-psubst/tick3.tests6
5 files changed, 50 insertions, 22 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 76737a234..b01f90370 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -234,6 +234,10 @@
234//usage:#define hush_full_usage "" 234//usage:#define hush_full_usage ""
235//usage:#define msh_trivial_usage NOUSAGE_STR 235//usage:#define msh_trivial_usage NOUSAGE_STR
236//usage:#define msh_full_usage "" 236//usage:#define msh_full_usage ""
237//usage:#define sh_trivial_usage NOUSAGE_STR
238//usage:#define sh_full_usage ""
239//usage:#define bash_trivial_usage NOUSAGE_STR
240//usage:#define bash_full_usage ""
237 241
238 242
239/* Build knobs */ 243/* Build knobs */
@@ -1367,9 +1371,15 @@ static void hush_exit(int exitcode)
1367#endif 1371#endif
1368} 1372}
1369 1373
1374
1370static int check_and_run_traps(int sig) 1375static int check_and_run_traps(int sig)
1371{ 1376{
1372 static const struct timespec zero_timespec; 1377 /* I want it in rodata, not in bss.
1378 * gcc 4.2.1 puts it in rodata only if it has { 0, 0 }
1379 * initializer. But other compilers may still use bss.
1380 * TODO: find more portable solution.
1381 */
1382 static const struct timespec zero_timespec = { 0, 0 };
1373 smalluint save_rcode; 1383 smalluint save_rcode;
1374 int last_sig = 0; 1384 int last_sig = 0;
1375 1385
@@ -3367,7 +3377,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
3367 3377
3368#if ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS 3378#if ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS
3369/* Subroutines for copying $(...) and `...` things */ 3379/* Subroutines for copying $(...) and `...` things */
3370static void add_till_backquote(o_string *dest, struct in_str *input); 3380static void add_till_backquote(o_string *dest, struct in_str *input, int in_dquote);
3371/* '...' */ 3381/* '...' */
3372static void add_till_single_quote(o_string *dest, struct in_str *input) 3382static void add_till_single_quote(o_string *dest, struct in_str *input)
3373{ 3383{
@@ -3399,7 +3409,7 @@ static void add_till_double_quote(o_string *dest, struct in_str *input)
3399 } 3409 }
3400 o_addchr(dest, ch); 3410 o_addchr(dest, ch);
3401 if (ch == '`') { 3411 if (ch == '`') {
3402 add_till_backquote(dest, input); 3412 add_till_backquote(dest, input, /*in_dquote:*/ 1);
3403 o_addchr(dest, ch); 3413 o_addchr(dest, ch);
3404 continue; 3414 continue;
3405 } 3415 }
@@ -3420,26 +3430,26 @@ static void add_till_double_quote(o_string *dest, struct in_str *input)
3420 * Example Output 3430 * Example Output
3421 * echo `echo '\'TEST\`echo ZZ\`BEST` \TESTZZBEST 3431 * echo `echo '\'TEST\`echo ZZ\`BEST` \TESTZZBEST
3422 */ 3432 */
3423static void add_till_backquote(o_string *dest, struct in_str *input) 3433static void add_till_backquote(o_string *dest, struct in_str *input, int in_dquote)
3424{ 3434{
3425 while (1) { 3435 while (1) {
3426 int ch = i_getch(input); 3436 int ch = i_getch(input);
3427 if (ch == EOF) {
3428 syntax_error_unterm_ch('`');
3429 /*xfunc_die(); - redundant */
3430 }
3431 if (ch == '`') 3437 if (ch == '`')
3432 return; 3438 return;
3433 if (ch == '\\') { 3439 if (ch == '\\') {
3434 /* \x. Copy both chars unless it is \` */ 3440 /* \x. Copy both unless it is \`, \$, \\ and maybe \" */
3435 int ch2 = i_getch(input); 3441 ch = i_getch(input);
3436 if (ch2 == EOF) { 3442 if (ch != '`'
3437 syntax_error_unterm_ch('`'); 3443 && ch != '$'
3438 /*xfunc_die(); - redundant */ 3444 && ch != '\\'
3445 && (!in_dquote || ch != '"')
3446 ) {
3447 o_addchr(dest, '\\');
3439 } 3448 }
3440 if (ch2 != '`' && ch2 != '$' && ch2 != '\\') 3449 }
3441 o_addchr(dest, ch); 3450 if (ch == EOF) {
3442 ch = ch2; 3451 syntax_error_unterm_ch('`');
3452 /*xfunc_die(); - redundant */
3443 } 3453 }
3444 o_addchr(dest, ch); 3454 o_addchr(dest, ch);
3445 } 3455 }
@@ -3504,7 +3514,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign
3504 continue; 3514 continue;
3505 } 3515 }
3506 if (ch == '`') { 3516 if (ch == '`') {
3507 add_till_backquote(dest, input); 3517 add_till_backquote(dest, input, /*in_dquote:*/ 0);
3508 o_addchr(dest, ch); 3518 o_addchr(dest, ch);
3509 continue; 3519 continue;
3510 } 3520 }
@@ -3818,7 +3828,7 @@ static int encode_string(o_string *as_string,
3818 //unsigned pos = dest->length; 3828 //unsigned pos = dest->length;
3819 o_addchr(dest, SPECIAL_VAR_SYMBOL); 3829 o_addchr(dest, SPECIAL_VAR_SYMBOL);
3820 o_addchr(dest, 0x80 | '`'); 3830 o_addchr(dest, 0x80 | '`');
3821 add_till_backquote(dest, input); 3831 add_till_backquote(dest, input, /*in_dquote:*/ dquote_end == '"');
3822 o_addchr(dest, SPECIAL_VAR_SYMBOL); 3832 o_addchr(dest, SPECIAL_VAR_SYMBOL);
3823 //debug_printf_subst("SUBST RES3 '%s'\n", dest->data + pos); 3833 //debug_printf_subst("SUBST RES3 '%s'\n", dest->data + pos);
3824 goto again; 3834 goto again;
@@ -4191,7 +4201,7 @@ static struct pipe *parse_stream(char **pstring,
4191 o_addchr(&dest, SPECIAL_VAR_SYMBOL); 4201 o_addchr(&dest, SPECIAL_VAR_SYMBOL);
4192 o_addchr(&dest, '`'); 4202 o_addchr(&dest, '`');
4193 pos = dest.length; 4203 pos = dest.length;
4194 add_till_backquote(&dest, input); 4204 add_till_backquote(&dest, input, /*in_dquote:*/ 0);
4195# if !BB_MMU 4205# if !BB_MMU
4196 o_addstr(&ctx.as_string, dest.data + pos); 4206 o_addstr(&ctx.as_string, dest.data + pos);
4197 o_addchr(&ctx.as_string, '`'); 4207 o_addchr(&ctx.as_string, '`');
diff --git a/shell/hush_test/hush-misc/heredoc_backslash1.right b/shell/hush_test/hush-misc/heredoc_backslash1.right
index 2633908fb..6a6114821 100644
--- a/shell/hush_test/hush-misc/heredoc_backslash1.right
+++ b/shell/hush_test/hush-misc/heredoc_backslash1.right
@@ -5,6 +5,8 @@ a\\
5 b 5 b
6 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 6 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
7 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 7 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
8 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
9 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
8c\ 10c\
9 11
10Unquoted heredoc: 12Unquoted heredoc:
@@ -13,6 +15,8 @@ a\
13 b 15 b
14 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- 16 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
15 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- 17 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
18 123456 v-$a-\t-\-\"-\x-`-\--\z-\*-\?-
19 123456 v-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-
16cEOF2 20cEOF2
17 21
18Quoted -heredoc: 22Quoted -heredoc:
@@ -22,6 +26,8 @@ a\\
22b 26b
23 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 27 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
24-$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 28-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
29 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
30 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
25c\ 31c\
26 32
27Unquoted -heredoc: 33Unquoted -heredoc:
@@ -30,6 +36,8 @@ a\
30b 36b
31 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?- 37 123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
32-qwerty-\t-\-\"-\'-`-\--\z-\*-\?- 38-qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
39 123456 v-$a-\t-\-\"-\x-`-\--\z-\*-\?-
40 123456 v-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-
33cEOF4 41cEOF4
34 42
35Done: 0 43Done: 0
diff --git a/shell/hush_test/hush-misc/heredoc_backslash1.tests b/shell/hush_test/hush-misc/heredoc_backslash1.tests
index 22045d42e..501af5490 100755
--- a/shell/hush_test/hush-misc/heredoc_backslash1.tests
+++ b/shell/hush_test/hush-misc/heredoc_backslash1.tests
@@ -11,6 +11,8 @@ a\\
11 b 11 b
12 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 12 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
13 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 13 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
14 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
15 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
14c\ 16c\
15EOF1 17EOF1
16echo 18echo
@@ -23,6 +25,8 @@ a\\
23 b 25 b
24 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 26 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
25 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 27 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
28 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'`
29 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-')
26c\ 30c\
27EOF2 31EOF2
28EOF2 32EOF2
@@ -36,6 +40,8 @@ a\\
36 b 40 b
37 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 41 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
38 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 42 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
43 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
44 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
39c\ 45c\
40 EOF3 46 EOF3
41# In -heredoc case the marker is detected even if it is indented. 47# In -heredoc case the marker is detected even if it is indented.
@@ -49,6 +55,8 @@ a\\
49 b 55 b
50 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 56 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
51 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- 57 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
58 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'`
59 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-')
52c\ 60c\
53EOF4 61EOF4
54 EOF4 62 EOF4
diff --git a/shell/hush_test/hush-psubst/tick3.right b/shell/hush_test/hush-psubst/tick3.right
index dc84e9263..00f267ae5 100644
--- a/shell/hush_test/hush-psubst/tick3.right
+++ b/shell/hush_test/hush-psubst/tick3.right
@@ -2,5 +2,5 @@
2$TEST 2$TEST
3Q 3Q
4a\bc 4a\bc
5a"c 511-$a-\t-\-\"-`-\--\z-\*-\?-22 33-$a-\t-\-"-`-\--\z-\*-\?-44
6done:0 6done:0
diff --git a/shell/hush_test/hush-psubst/tick3.tests b/shell/hush_test/hush-psubst/tick3.tests
index 469c43c27..3aeb241c3 100755
--- a/shell/hush_test/hush-psubst/tick3.tests
+++ b/shell/hush_test/hush-psubst/tick3.tests
@@ -7,6 +7,8 @@ echo `echo '\'TEST\`echo ZZ\`BEST`
7echo `echo \\$TEST` 7echo `echo \\$TEST`
8echo `echo \$TEST` 8echo `echo \$TEST`
9echo a`echo \\\\b`c 9echo a`echo \\\\b`c
10# \" etc are NOT special (passed verbatim WITH \)! 10
11echo a`echo \"`c 11# \" is not special if in unquoted `cmd` (passed verbatim WITH \),
12# but is special in quoted one
13echo `echo 11'-$a-\t-\\-\"-\`-\--\z-\*-\?-'22` "`echo 33'-$a-\t-\\-\"-\`-\--\z-\*-\?-'44`"
12echo done:$? 14echo done:$?