Commit Graph

23 Commits

Author SHA1 Message Date
Denys Vlasenko
63c42afaa4 hush: add "heredoc.tests" from ash, tweak ash "is a function" message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24 17:10:18 +02:00
Denys Vlasenko
41ef41b3e0 hush: fix nested redirects colliding with script fds
This necessitates switch from libc FILE api to a simple
homegrown replacement.
The change which fixes the bug here is the deleting of

	restore_redirected_FILEs();

line. It was prematurely moving (restoring) script fd#3.
The fix is: we don't even _want_ to restore scrit fds,
we are perfectly fine with them being moved.
The only reason we tried to restore them is that FILE api
did not allow moving of FILE->fd.

function                                             old     new   delta
refill_HFILE_and_getc                                  -      93     +93
hfopen                                                 -      90     +90
hfclose                                                -      66     +66
pseudo_exec_argv                                     591     597      +6
hush_main                                           1089    1095      +6
builtin_source                                       209     214      +5
save_fd_on_redirect                                  197     200      +3
setup_redirects                                      320     321      +1
fgetc_interactive                                    235     236      +1
i_peek_and_eat_bkslash_nl                             99      97      -2
expand_vars_to_list                                 1103    1100      -3
restore_redirects                                     99      52     -47
fclose_and_forget                                     57       -     -57
remember_FILE                                         63       -     -63
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 6/3 up/down: 271/-172)           Total: 99 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24 16:54:41 +02:00
Denys Vlasenko
dfc7394763 hush: handle backslash-newline in heredoc terminators
function                                             old     new   delta
fetch_heredocs                                       479     527     +48

(ash fails this test)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24 14:03:18 +02:00
Denys Vlasenko
474cb20555 hush: fix handling of heredocs not enclosed in groups where they are "declared"
function                                             old     new   delta
fetch_heredocs                                         -     479    +479
parse_and_run_stream                                 146     148      +2
parse_stream                                        2787    2296    -491
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 481/-491)          Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-24 13:03:03 +02:00
Denys Vlasenko
3675c37b9b hush: fix heredoc handling in the "cmd <<EOF ;<newline>" case
function                                             old     new   delta
parse_stream                                        2759    2787     +28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-23 16:31:21 +02:00
Denys Vlasenko
d73cdbf84c hush: fix handling of heredocs starting with empty lines
function                                             old     new   delta
parse_stream                                        2748    2759     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-23 15:43:57 +02:00
Denys Vlasenko
c4c2012284 ash: parser: Fix single-quoted patterns in here-documents
Upstream commit:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 23:07:53 +0800
    parser: Fix single-quoted patterns in here-documents

    The script

            x=*
            cat <<- EOF
                    ${x#'*'}
            EOF

    prints * instead of nothing as it should.  The problem is that
    when we're in sqsyntax context in a here-document, we won't add
    CTLESC as we should.  This patch fixes it:

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:29:20 +02:00
Denys Vlasenko
41fddb4372 parser: Fix backquote support in here-document EOF mark
Upstream commit:

    Author: Herbert Xu <herbert@gondor.apana.org.au>
    Date:   Thu Mar 15 18:27:30 2018 +0800
    parser: Fix backquote support in here-document EOF mark

    Currently using backquotes in a here-document EOF mark is broken
    because dash tries to do command substitution on it.  This patch
    fixes it by checking whether we're looking for an EOF mark during
    tokenisation.

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

With added fix for quoted-ness of the EOF mark.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 16:38:32 +02:00
Denys Vlasenko
220be537a0 ash: use pgetc_eatbnl() in more places
Part of upstream commit:

    Date:   Thu Mar 8 08:37:11 2018 +0100
    Author: Harald van Dijk <harald@gigawatt.nl>
    parser: use pgetc_eatbnl() in more places

    dash has a pgetc_eatbnl function in parser.c which skips any
    backslash-newline combinations. It's not used everywhere it could be.
    There is also some duplicated backslash-newline handling elsewhere in
    parser.c. Replace most of the calls to pgetc() with calls to
    pgetc_eatbnl() and remove the duplicated backslash-newline handling.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Not adding "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes, since
readtoken1() handles the "starts with backslash + newline" case itself.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-31 19:40:56 +02:00
Denys Vlasenko
0f018b3070 hush: fix handling of empty heredoc EOF marker
function                                             old     new   delta
parse_stream                                        2609    2634     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 20:43:26 +02:00
Denys Vlasenko
a732898fdd ash: [PARSER] Removed noexpand/length check on eofmark
Upstream comment:

	Date: Sun, 11 Nov 2007 14:21:23 +0800
	[PARSER] Removed noexpand/length check on eofmark

	On Tue, Oct 30, 2007 at 04:23:35AM +0000, Oleg Verych wrote:
	>
	> } 8<<""
	> ======================

	Actually this (the empty delim) only works with dash by accident.
	I've tried bash and pdksh and they both terminate on the first
	empty line which is what you would expect rather than EOF.  The
	real Korn shell does something completely different.

	I've fixed this in dash to conform to bash/pdksh.

	> In [0] it's stated, that delimiter isn't evaluated (expanded), only
	> quoiting must be checked. That if() seems to be completely bogus.

	OK I agree.  The reason it was there is because the parser would
	have already replaced the dollar sign by an internal representation.

	I've fixed it properly with this patch.

	Test case:

	        cat <<- $a
	                OK
	        $a

	        cat <<- ""
	                OK

	        echo OK

	Old result:

	        dash: Syntax error: Illegal eof marker for << redirection
	        OK

	        echo OK

	New result:

	        OK
	        OK
	        OK

function                                             old     new   delta
parsefname                                           227     152     -75
readtoken1                                          2819    2651    -168
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-243)           Total: -243 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29 19:57:28 +02:00
Denys Vlasenko
bb963bda62 shell: syncronize ash and hush heredoc3.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:19:35 +02:00
Denys Vlasenko
959cb67428 shell: syncronize ash and hush heredoc1.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:16:18 +02:00
Denys Vlasenko
350e686f3b ash: [PARSER] Recognise here-doc delimiters terminated by EOF
Upstream commit 1:

    Date: Wed, 26 Sep 2007 17:14:16 +0800
    [PARSER] Recognise here-doc delimiters terminated by EOF

    Previously dash required a <newline> character to be present in order for
    a here-document delimiter to be detected.  Allowing EOF in the absence of
    a <newline> to play the same purpose allows some intuitive scripts to
    succeed.  POSIX seems to be silence on this so this should be OK.

    Test case:

        eval 'cat <<- NOT
                test
        NOT'
        echo OK

    Old result:

        test
        NOTOK

    New result:

        test
        OK

Upstream commit 2:

    Date: Sat, 20 Oct 2007 18:49:31 +0800
    [PARSER] Fix here-doc corruption

    The change

        [PARSER] Recognise here-doc delimiters terminated by EOF

    introduced a regerssion whereby lines starting with eofmark but are not equal
    to eofmark would be corrupted.  This patch fixes it.

    Test case:

        cat << _ACEOF
        _ASBOX
        _ACEOF

    Old result:

        SASBOX

    New result:

        _ASBOX

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 16:26:45 +02:00
Denys Vlasenko
a62bc80571 ash testsuite: add most of hust tests which pass for ash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:06:55 +02:00
Denys Vlasenko
1b73f8471a sh testsuite: create hush-heredoc/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:49:46 +02:00
Ron Yorston
84ba50c32f ash: bash-compatible $'...' shouldn't expand in double quotes
Bash doesn't expand its $'...' construct in double quotes:

   $ echo "$'a\tb'"
   $'a\tb'

Change BusyBox ash to do the same.  This also fixes a problem with
here documents where BusyBox ash gave an incorrect result for:

   $ cat <<EOF
   > '$'
   > EOF
   '$'

Reported-by: Timo Teras <timo.teras@iki.fi>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-15 22:16:46 +02:00
Ron Yorston
713f07d906 ash: fix error during recursive processing of here document
Save the value of the checkkwd flag to prevent it being clobbered
during recursion.

Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken                                            190     203     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:45:36 +01:00
Ron Yorston
9121510dc6 ash: add test for issue with here document
This used to work but doesn't now:

foo () {
cat <<EOF && { echo "$1" ; }
$1
EOF
}

foo "bar"

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:12:03 +01:00
Denys Vlasenko
0a0acb55db ash: fix handling of duplicate "local"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-18 19:36:38 +02:00
Denys Vlasenko
7e66102f76 ash: fix a SEGV case in an invalid heredoc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-05 21:00:17 +01:00
Denis Vlasenko
c86e052b81 fix accumulated whitespace and indentation damage 2007-03-20 11:30:28 +00:00
Denis Vlasenko
9431e564aa ash: "here document" testcases 2007-03-05 21:08:29 +00:00