ash: expand: Fix multiple issues with EXP_DISCARD in evalvar
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 22 Feb 2020 18:38:40 +0000 (19:38 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 24 Feb 2020 18:20:51 +0000 (19:20 +0100)
commit1555895b4af44ce47fe2365aec82e8e67c685f08
treebd821be779bc1d489ac966b0d83e4a5e026979dd
parent823318822ccb0e0910abbd4e1f983637dfd9d3c0
ash: expand: Fix multiple issues with EXP_DISCARD in evalvar

Upstream commit:

    Date: Wed, 12 Sep 2018 14:27:16 +0800
    expand: Fix multiple issues with EXP_DISCARD in evalvar

    The commit 3cd538634f71538370f5af239f342aec48b7470b broke parameter
    expansion in multiple ways because the EXP_DISCARD flag wasn't set
    or tested for various cases:

            $ src/dash -c 'var=; echo ${var:+nonempty}'
            nonempty
            $ src/dash -u -c 'unset foo bar; echo ${foo+${bar}}'
            dash: 1: bar: parameter not set
            $ src/dash -c 'foo=bar; echo ${foo=BUG}; echo $foo'
            barBUG
            bar
            $

    This patch fixes them by introducing a new discard variable that
    tracks whether the extra word should be discarded or not when it
    is parsed.

Reported-by: Martijn Dekker <martijn@inlv.org>
    Fixes: 3cd538634f71 ("expand: Do not reprocess data when...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c