bug-bash
[Top][All Lists]
Advanced

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

Bug in syntax checking causes unintended running of a function


From: David Maas
Subject: Bug in syntax checking causes unintended running of a function
Date: Tue, 19 Apr 2016 07:45:27 -0700

Running the echo and other contents of the function really doesn't seem like the correct behavior. If the function isn't called, then its contents shouldn't be executed. 

Hypothetically, what if the author was partway through writing a backup script that removes backed up data? The behavior of bash in this instance could cause a serious problem.

- David

On Mon, Apr 18, 2016 at 8:38 PM, konsolebox <address@hidden> wrote:
On Tue, Apr 19, 2016 at 3:52 AM, David Maas <address@hidden> 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.
>
>
> -------------- Script --------------
>
> #!/bin/bash
> #Should be avg=((avg+6))
>
> function neverrunme
> {
>     avg=0
>     avg=(($avg+6))
>     echo -n "This function was never called. Bash version:"
>     /bin/bash --version | head -1
> }
>
> echo "Welcome to this demonstration."
>
> -------------- Output --------------
>
>
> address@hidden ~]$ ./test-file.sh
> ./test-file.sh: line 7: syntax error near unexpected token `('
> ./test-file.sh: line 7: `    avg=(($avg+6))'
> This function was never called. Bash version:GNU bash, version
> 4.2.46(1)-release (x86_64-redhat-linux-gnu)
> ./test-file.sh: line 10: syntax error near unexpected token `}'
> ./test-file.sh: line 10: `}'

It didn't run the function. The function-syntax-checking scope simply
ended in `avg=(($avg+6))`.


reply via email to

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