parser: Catch errors in expandstr
commit50fc8edbe2532b573f2edb727861e3649b9dafef
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 28 Apr 2020 06:17:58 +0000 (28 16:17 +1000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 15 May 2020 06:24:37 +0000 (15 16:24 +1000)
tree80f81a8976bc307ec7f57ef3b5e5e5a9b5436ba0
parenta256b373624d3c6c6f38bce03b58cc38fab7e1e2
parser: Catch errors in expandstr

On Fri, Dec 13, 2019 at 02:51:34PM +0000, Simon Ser wrote:
> Just noticed another dash bug: when setting invalid PS1 values dash
> enters an infinite loop.
>
> For instance, setting PS1='$(' makes dash print many of these:
>
>    dash: 1: Syntax error: end of file unexpected (expecting ")")
>
> It would be nice to fallback to the default PS1 value on error.

This patch fixes it by using the literal value of PS1 should an
error occur during expansion.

On Wed, Feb 26, 2020 at 09:12:04PM +0000, Ron Yorston wrote:
>
> There's another case that should be handled.  PS1='`xxx(`' causes the
> shell to exit because the old-style backquote leaves an additional file
> on the stack.

Ron's change has been folded into this patch.

Reported-by: Simon Ser <contact@emersion.fr>
Reported-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
src/parser.c