bug-bash
[Top][All Lists]
Advanced

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

Re: Bug in syntax checking causes unintended running of a function


From: Chet Ramey
Subject: Re: Bug in syntax checking causes unintended running of a function
Date: Tue, 19 Apr 2016 08:36:45 -0700
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.7.2

On 4/18/16 12:52 PM, David Maas wrote:
> Hi! I found a bug in bash, I've checked versions 4.1 (centos 6.7), 4.2
> (centos 7.2), and 4.3.30 (from the ftp site). The bug is that if you do a
> double parenthesis math thing with the wrong syntax, the script runs the
> function during what I assume is syntax checking. Demonstration script is
> attached.

That's close to, but not exactly, what's happening.

The shell attempts to parse a function and encounters a syntax error.  It
has a choice at this point: abandon parsing of the current command (the
function definition), or abandon the script altogether.

In its default mode, bash chooses the former: abandon parsing the function
definition and go on.  In Posix mode, it abandons the script entirely.
When it attempts to go on, it synchronizes with the next newline and
attempts to parse a new command (`echo ...'), which it does successfully.
When it hits the close brace that was intended to end the function
definition, that's an operator an a place where it's disallowed, which
generates another syntax error.

Chet

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



reply via email to

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