hush: fix another corner case with backslashes in heredocs
function old new delta parse_stream 2395 2432 +37 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
parent
77b32ccbf2
commit
c3adfacd22
10
shell/hush.c
10
shell/hush.c
@ -3174,6 +3174,7 @@ static char *fetch_till_str(o_string *as_string,
|
|||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
nommu_addchr(as_string, ch);
|
nommu_addchr(as_string, ch);
|
||||||
if (ch == '\n'
|
if (ch == '\n'
|
||||||
|
/* TODO: or EOF? (heredoc delimiter may end with <eof>, not only <eol> */
|
||||||
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
|
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
|
||||||
) {
|
) {
|
||||||
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
||||||
@ -3182,7 +3183,8 @@ static char *fetch_till_str(o_string *as_string,
|
|||||||
return heredoc.data;
|
return heredoc.data;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
o_addchr(&heredoc, ch);
|
o_addchr(&heredoc, '\n');
|
||||||
|
prev = 0; /* not \ */
|
||||||
past_EOL = heredoc.length;
|
past_EOL = heredoc.length;
|
||||||
jump_in:
|
jump_in:
|
||||||
do {
|
do {
|
||||||
@ -3196,8 +3198,12 @@ static char *fetch_till_str(o_string *as_string,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
o_addchr(&heredoc, ch);
|
o_addchr(&heredoc, ch);
|
||||||
|
if (prev == '\\' && ch == '\\')
|
||||||
|
/* Correctly handle foo\\<eol> (not a line cont.) */
|
||||||
|
prev = 0; /* not \ */
|
||||||
|
else
|
||||||
|
prev = ch;
|
||||||
nommu_addchr(as_string, ch);
|
nommu_addchr(as_string, ch);
|
||||||
prev = ch;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,24 @@
|
|||||||
Quoted heredoc:
|
Quoted heredoc:
|
||||||
a\
|
a\
|
||||||
b
|
b
|
||||||
|
a\\
|
||||||
|
b
|
||||||
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
c\
|
c\
|
||||||
|
|
||||||
Unquoted heredoc:
|
Unquoted heredoc:
|
||||||
a b
|
a b
|
||||||
|
a\
|
||||||
|
b
|
||||||
123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
||||||
-qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
-qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
||||||
cEOF2
|
cEOF2
|
||||||
|
|
||||||
Quoted -heredoc:
|
Quoted -heredoc:
|
||||||
a\
|
a\
|
||||||
|
b
|
||||||
|
a\\
|
||||||
b
|
b
|
||||||
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
@ -20,6 +26,8 @@ c\
|
|||||||
|
|
||||||
Unquoted -heredoc:
|
Unquoted -heredoc:
|
||||||
a b
|
a b
|
||||||
|
a\
|
||||||
|
b
|
||||||
123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
123456 -qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
||||||
-qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
-qwerty-\t-\-\"-\'-`-\--\z-\*-\?-
|
||||||
cEOF4
|
cEOF4
|
||||||
|
@ -7,6 +7,8 @@ echo Quoted heredoc:
|
|||||||
cat <<"EOF1"
|
cat <<"EOF1"
|
||||||
a\
|
a\
|
||||||
b
|
b
|
||||||
|
a\\
|
||||||
|
b
|
||||||
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
c\
|
c\
|
||||||
@ -17,6 +19,8 @@ echo Unquoted heredoc:
|
|||||||
cat <<EOF2
|
cat <<EOF2
|
||||||
a\
|
a\
|
||||||
b
|
b
|
||||||
|
a\\
|
||||||
|
b
|
||||||
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
c\
|
c\
|
||||||
@ -28,6 +32,8 @@ echo Quoted -heredoc:
|
|||||||
cat <<-"EOF3"
|
cat <<-"EOF3"
|
||||||
a\
|
a\
|
||||||
b
|
b
|
||||||
|
a\\
|
||||||
|
b
|
||||||
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
c\
|
c\
|
||||||
@ -39,6 +45,8 @@ echo Unquoted -heredoc:
|
|||||||
cat <<-EOF4
|
cat <<-EOF4
|
||||||
a\
|
a\
|
||||||
b
|
b
|
||||||
|
a\\
|
||||||
|
b
|
||||||
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
|
||||||
c\
|
c\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user