aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-03-31 20:16:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-03-31 20:16:31 +0200
commita94eeb0b4222de7f05594c93ffdd84faea5b8e2d (patch)
treefc12b936422601f12fb9288176636c391a335e76
parent220be537a03f029e1e619003d6f7def10103a156 (diff)
downloadbusybox-w32-a94eeb0b4222de7f05594c93ffdd84faea5b8e2d.tar.gz
busybox-w32-a94eeb0b4222de7f05594c93ffdd84faea5b8e2d.tar.bz2
busybox-w32-a94eeb0b4222de7f05594c93ffdd84faea5b8e2d.zip
hush: fix heredoc_bkslash_newline1.tests failure
function old new delta parse_stream 2787 2827 +40 builtin_type 117 115 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c77
1 files changed, 42 insertions, 35 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 01d8f5935..533d45ac3 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2694,6 +2694,42 @@ static int i_peek2(struct in_str *i)
2694 return ch; 2694 return ch;
2695} 2695}
2696 2696
2697static int i_getch_and_eat_bkslash_nl(struct in_str *input)
2698{
2699 for (;;) {
2700 int ch, ch2;
2701
2702 ch = i_getch(input);
2703 if (ch != '\\')
2704 return ch;
2705 ch2 = i_peek(input);
2706 if (ch2 != '\n')
2707 return ch;
2708 /* backslash+newline, skip it */
2709 i_getch(input);
2710 }
2711}
2712
2713/* Note: this function _eats_ \<newline> pairs, safe to use plain
2714 * i_getch() after it instead of i_getch_and_eat_bkslash_nl().
2715 */
2716static int i_peek_and_eat_bkslash_nl(struct in_str *input)
2717{
2718 for (;;) {
2719 int ch, ch2;
2720
2721 ch = i_peek(input);
2722 if (ch != '\\')
2723 return ch;
2724 ch2 = i_peek2(input);
2725 if (ch2 != '\n')
2726 return ch;
2727 /* backslash+newline, skip it */
2728 i_getch(input);
2729 i_getch(input);
2730 }
2731}
2732
2697static void setup_file_in_str(struct in_str *i, FILE *f) 2733static void setup_file_in_str(struct in_str *i, FILE *f)
2698{ 2734{
2699 memset(i, 0, sizeof(*i)); 2735 memset(i, 0, sizeof(*i));
@@ -4014,7 +4050,7 @@ static int parse_redirect(struct parse_context *ctx,
4014 if (dup_num == REDIRFD_SYNTAX_ERR) 4050 if (dup_num == REDIRFD_SYNTAX_ERR)
4015 return 1; 4051 return 1;
4016 } else { 4052 } else {
4017 int ch = i_peek(input); 4053 int ch = i_peek_and_eat_bkslash_nl(input);
4018 dup_num = (ch == '-'); /* HEREDOC_SKIPTABS bit is 1 */ 4054 dup_num = (ch == '-'); /* HEREDOC_SKIPTABS bit is 1 */
4019 if (dup_num) { /* <<-... */ 4055 if (dup_num) { /* <<-... */
4020 ch = i_getch(input); 4056 ch = i_getch(input);
@@ -4024,7 +4060,7 @@ static int parse_redirect(struct parse_context *ctx,
4024 } 4060 }
4025 4061
4026 if (style == REDIRECT_OVERWRITE && dup_num == REDIRFD_TO_FILE) { 4062 if (style == REDIRECT_OVERWRITE && dup_num == REDIRFD_TO_FILE) {
4027 int ch = i_peek(input); 4063 int ch = i_peek_and_eat_bkslash_nl(input);
4028 if (ch == '|') { 4064 if (ch == '|') {
4029 /* >|FILE redirect ("clobbering" >). 4065 /* >|FILE redirect ("clobbering" >).
4030 * Since we do not support "set -o noclobber" yet, 4066 * Since we do not support "set -o noclobber" yet,
@@ -4343,39 +4379,6 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
4343 /* command remains "open", available for possible redirects */ 4379 /* command remains "open", available for possible redirects */
4344} 4380}
4345 4381
4346static int i_getch_and_eat_bkslash_nl(struct in_str *input)
4347{
4348 for (;;) {
4349 int ch, ch2;
4350
4351 ch = i_getch(input);
4352 if (ch != '\\')
4353 return ch;
4354 ch2 = i_peek(input);
4355 if (ch2 != '\n')
4356 return ch;
4357 /* backslash+newline, skip it */
4358 i_getch(input);
4359 }
4360}
4361
4362static int i_peek_and_eat_bkslash_nl(struct in_str *input)
4363{
4364 for (;;) {
4365 int ch, ch2;
4366
4367 ch = i_peek(input);
4368 if (ch != '\\')
4369 return ch;
4370 ch2 = i_peek2(input);
4371 if (ch2 != '\n')
4372 return ch;
4373 /* backslash+newline, skip it */
4374 i_getch(input);
4375 i_getch(input);
4376 }
4377}
4378
4379#if ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS 4382#if ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS
4380/* Subroutines for copying $(...) and `...` things */ 4383/* Subroutines for copying $(...) and `...` things */
4381static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote); 4384static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote);
@@ -5181,6 +5184,8 @@ static struct pipe *parse_stream(char **pstring,
5181 goto parse_error; 5184 goto parse_error;
5182 } 5185 }
5183 redir_style = REDIRECT_OVERWRITE; 5186 redir_style = REDIRECT_OVERWRITE;
5187 if (next == '\\')
5188 next = i_peek_and_eat_bkslash_nl(input);
5184 if (next == '>') { 5189 if (next == '>') {
5185 redir_style = REDIRECT_APPEND; 5190 redir_style = REDIRECT_APPEND;
5186 ch = i_getch(input); 5191 ch = i_getch(input);
@@ -5201,6 +5206,8 @@ static struct pipe *parse_stream(char **pstring,
5201 goto parse_error; 5206 goto parse_error;
5202 } 5207 }
5203 redir_style = REDIRECT_INPUT; 5208 redir_style = REDIRECT_INPUT;
5209 if (next == '\\')
5210 next = i_peek_and_eat_bkslash_nl(input);
5204 if (next == '<') { 5211 if (next == '<') {
5205 redir_style = REDIRECT_HEREDOC; 5212 redir_style = REDIRECT_HEREDOC;
5206 heredoc_cnt++; 5213 heredoc_cnt++;