bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOF while in parse_matched_pair closes interactive shell


From: Chet Ramey
Subject: Re: EOF while in parse_matched_pair closes interactive shell
Date: Tue, 21 Feb 2023 16:21:39 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

On 2/21/23 3:59 PM, Eduardo A. Bustamante López wrote:
On Tue, Feb 21, 2023 at 11:03:59AM -0500, Chet Ramey wrote:
(...)
The shell should exit on EOF. Previous versions relied on undocumented
bison behavior, which resulted in a token that wasn't handled by the
grammar.

Thank you for reviewing this and for the explanation. I initially thought this
changed as a result of this change:

| parse.y
|     - yylex: return YYUNDEF as current_token if read_token returns < 0.
|       Fixes parser reset issue reported by Todd Stein <toddbstein@gmail.com>
|       in https://savannah.gnu.org/support/index.php?110745

I changed `yylex' to return -1 the way it was, and it doesn't make a difference
in this case.

That's more or less the issue. Bash shouldn't return < 0 from yylex; bison
is allowed to translate it to YYEOF. YYEOF wasn't handled by the grammar,
so the shell reported a syntax error, and turned off EOF_Reached as a
result. Now, read_token will return -1 in more cases than EOF, and those
are the ones that need YYUNDEF, but YYEOF is appropriate in this one.

The shell should exit in this case, or at least run through the IGNOREEOF
processing in an interactive shell.

Despite its name, `report_syntax_error' does more than
that. It'll actually clear `EOF_Reached' when the shell is interactive:

Yeah, that's the bad part. But it's always done that.


If there's a bug here, it's that interactive shells need to handle
IGNOREEOF in this case.

Thanks for reminding me about IGNOREEOF. It does seem like `parse_matched_pair'
doesn't work with `ignoreeof' in this case. I suppose that's because the parser
doesn't see `yacc_EOF', so it never calls `handle_eof_input_unit'.

Right, we need to explicitly treat it as YYEOF instead of relying on bison
to do that for us. There needs to be a rule that includes YYEOF to handle
it. It can't be yacc_EOF because that's a potential simple command
terminator and we don't want to execute any partial command in this case.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]