Re: Comma expression in arithmetic evaluation referring to arrays make bash crash.

2016-02-15 Thread Stephane Chazelas
[...]
> Reproduced with 4.2.53 on Debian:
[...]



Actually, it was already reported in early 2013 and fixed for
4.3:

http://thread.gmane.org/gmane.comp.shells.bash.bugs/19384

-- 
Stephane



Re: Comma expression in arithmetic evaluation referring to arrays make bash crash.

2016-02-15 Thread Stephane Chazelas
2016-02-15 09:31:57 -0500, Chet Ramey:
> On 2/15/16 8:57 AM, Pontus Stenström wrote:
> 
> > Bash Version: 4.2
> > Patch Level: 24
> > Release Status: release
> > 
> > Description:
> > Comma expression in arithmetic evaluation referring to arrays make bash
> > crash.
> > 
> > Repeat-By:
> > This works fine:
> > ((c=3, d=4))
> > This crashes my bash:
> > a=(2 3 4 5)# OK
> > ((c=a[3], d=a[2])) # Crash
> 
> It runs fine on bash-4.3.42 on RHEL 5 and Mac OS X.
[...]

Reproduced with 4.2.53 on Debian:

Starting program: bash4.2.53 -c a=\(1\ 2\ 3\ 4\ 5\ 6\)\;\ \(\(b=a\[3\],\ 
c=a\[4\]\)\)\;\ typeset\ -p\ b\ c

Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/x86_64/strlen.S:106
106 ../sysdeps/x86_64/strlen.S: No such file or directory.
(gdb) bt
#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x0043c952 in expr_bind_array_element (tok=tok@entry=0x6f5328 "c", 
ind=ind@entry=3, rhs=rhs@entry=0x6f5318 "5") at expr.c:331
#2  0x0043e2c8 in expassign () at expr.c:531
#3  0x0043d532 in expcomma () at expr.c:441
#4  0x0043d736 in subexpr (expr=0x6fb7c8 "b=a[3], c=a[4]") at expr.c:419
#5  0x0043e5ca in evalexp (expr=0x6fb7c8 "b=a[3], c=a[4]", 
validp=0x7fffda90) at expr.c:384
#6  0x004321d8 in execute_arith_command (arith_command=, 
arith_command=) at execute_cmd.c:3309
#7  execute_command_internal (command=0x6fb508, asynchronous=0, 
pipe_in=7320904, pipe_out=0, fds_to_close=0x6fdc88) at execute_cmd.c:901
#8  0x00432859 in execute_connection (fds_to_close=, 
pipe_out=, pipe_in=, asynchronous=,
command=) at execute_cmd.c:2326
#9  execute_command_internal (command=0x6fb5c8, asynchronous=0, pipe_in=-1, 
pipe_out=-1, fds_to_close=0x6fb7a8) at execute_cmd.c:891
#10 0x00433fce in execute_command (command=0x6fb5c8) at 
execute_cmd.c:382
#11 0x0043281e in execute_connection (fds_to_close=, 
pipe_out=, pipe_in=, asynchronous=,
command=) at execute_cmd.c:2324
#12 execute_command_internal (command=0x6fb748, asynchronous=0, pipe_in=-1, 
pipe_out=-1, fds_to_close=0x6fb788) at execute_cmd.c:891
#13 0x00471024 in parse_and_execute (string=, 
from_file=from_file@entry=0x4a990d "-c", flags=flags@entry=4) at 
evalstring.c:340
#14 0x0041d9ba in run_one_command (command=) at 
shell.c:1315
#15 0x0041c786 in main (argc=3, argv=0x7fffdf78, 
env=0x7fffdf98) at shell.c:688

See how it calls expr_bind_array_element on "c" as if it wanted
to assign something to c[3] instead of c. The 3 looks like it
comes from the previous a[3] expansion.

-- 
Stephane



Re: Comma expression in arithmetic evaluation referring to arrays make bash crash.

2016-02-15 Thread Pontus Stenström
Thanks,
it also works fine in GNU bash, version 4.3.42(4)-release (i686-pc-cygwin)
Sorry for troubbling you, I will upgrade my bash.
Regards -- Pontus



From:   Greg Wooledge <wool...@eeg.ccf.org>
To: Chet Ramey <chet.ra...@case.edu>
Cc: Pontus Stenström <pontus.stenst...@mycronic.com>, bug-bash@gnu.org
Date:   2016-02-15 15:47
Subject:Re: Comma expression in arithmetic evaluation referring to 
arrays make bash crash.



On Mon, Feb 15, 2016 at 09:31:57AM -0500, Chet Ramey wrote:
> On 2/15/16 8:57 AM, Pontus Stenström wrote:
> 
> > Bash Version: 4.2
> > Patch Level: 24
> > Release Status: release
> > 
> > Description:
> > Comma expression in arithmetic evaluation referring to arrays make 
bash
> > crash.
> > 
> > Repeat-By:
> > This works fine:
> > ((c=3, d=4))
> > This crashes my bash:
> > a=(2 3 4 5)# OK
> > ((c=a[3], d=a[2])) # Crash
> 
> It runs fine on bash-4.3.42 on RHEL 5 and Mac OS X.

On HP-UX, it doesn't crash, but doesn't work quite right either:

imadev:~$ bash-4.2 -c 'echo "$BASH_VERSION"; a=(2 3 4 5); ((c=a[3], 
d=a[2])); declare -p a c d'
4.2.46(1)-release
declare -a a='([0]="2" [1]="3" [2]="4" [3]="5")'
declare -- c="5"
bash-4.2: line 0: declare: d: not found

4.2 is the second-newest release, but 4.2.24 is 29 patches behind.
The current patch level for 4.2 is 4.2.53.  I'm apparently a bit behind
the current patch level as well.

It works in 4.3, as Chet said.





You are hereby formally notified that all information contained in this 
communication and any attachments shall be deemed strictly confidential 
and privileged unless explicitly stated otherwise. Please note that your 
use of confidential information may be governed, and restricted, by a 
non-disclosure agreement. The information contained in this communication 
and any attachments is disclosed for the sole use of the intended 
recipient(s). If you are not the intended recipient, you are hereby 
formally notified that any unauthorized review, use, disclosure or 
distribution of this message is prohibited. Please notify the sender 
immediately by replying to this message and destroy all copies of this 
message and any attachments. Mycronic is neither liable for the proper and 
complete transmission of the information contained in this communication, 
nor for any delay in its receipt.



Re: Comma expression in arithmetic evaluation referring to arrays make bash crash.

2016-02-15 Thread Greg Wooledge
On Mon, Feb 15, 2016 at 09:31:57AM -0500, Chet Ramey wrote:
> On 2/15/16 8:57 AM, Pontus Stenström wrote:
> 
> > Bash Version: 4.2
> > Patch Level: 24
> > Release Status: release
> > 
> > Description:
> > Comma expression in arithmetic evaluation referring to arrays make bash
> > crash.
> > 
> > Repeat-By:
> > This works fine:
> > ((c=3, d=4))
> > This crashes my bash:
> > a=(2 3 4 5)# OK
> > ((c=a[3], d=a[2])) # Crash
> 
> It runs fine on bash-4.3.42 on RHEL 5 and Mac OS X.

On HP-UX, it doesn't crash, but doesn't work quite right either:

imadev:~$ bash-4.2 -c 'echo "$BASH_VERSION"; a=(2 3 4 5); ((c=a[3], d=a[2])); 
declare -p a c d'
4.2.46(1)-release
declare -a a='([0]="2" [1]="3" [2]="4" [3]="5")'
declare -- c="5"
bash-4.2: line 0: declare: d: not found

4.2 is the second-newest release, but 4.2.24 is 29 patches behind.
The current patch level for 4.2 is 4.2.53.  I'm apparently a bit behind
the current patch level as well.

It works in 4.3, as Chet said.



Re: Comma expression in arithmetic evaluation referring to arrays make bash crash.

2016-02-15 Thread Chet Ramey
On 2/15/16 8:57 AM, Pontus Stenström wrote:

> Bash Version: 4.2
> Patch Level: 24
> Release Status: release
> 
> Description:
>     Comma expression in arithmetic evaluation referring to arrays make bash
> crash.
> 
> Repeat-By:
> This works fine:
> ((c=3, d=4))
> This crashes my bash:
> a=(2 3 4 5)# OK
> ((c=a[3], d=a[2])) # Crash

It runs fine on bash-4.3.42 on RHEL 5 and Mac OS X.

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



Comma expression in arithmetic evaluation referring to arrays make bash crash.

2016-02-15 Thread Pontus Stenström
 Configuration Information [Automatically generated, do not change]:Machine: x86_64OS: linux-gnuCompiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.2 -L/home/abuild/rpmbuild/BUILD/bash-4.2/../readline-6.2Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-suse-linux-gnu' -DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g  -D_GNU_SOURCE -DRECYCLES_PIDS -Wall -g -std=gnu89 -Wuninitialized -Wextra -Wno-unprototyped-calls -Wno-switch-enum -Wno-unused-variable -Wno-unused-parameter -ftree-loop-linear -pipe -fprofile-useuname output: Linux urd 3.4.11-2.16-desktop #1 SMP PREEMPT Wed Sep 26 17:05:00 UTC 2012 (259fc87) x86_64 x86_64 x86_64 GNU/LinuxMachine Type: x86_64-suse-linux-gnuBash Version: 4.2Patch Level: 24Release Status: releaseDescription:    Comma _expression_ in arithmetic evaluation referring to arrays make bash crash.Repeat-By:    This works fine:    ((c=3, d=4))    This crashes my bash:    a=(2 3 4 5)    # OK    ((c=a[3], d=a[2])) # CrashWarning: Program '/bin/bash' crashed.You are hereby formally notified that all information contained in this communication and any attachments shall be deemed strictly confidential and privileged unless explicitly stated otherwise. Please note that your use of confidential information may be governed, and restricted, by a non-disclosure agreement. The information contained in this communication and any attachments is disclosed for the sole use of the intended recipient(s). If you are not the intended recipient, you are hereby formally notified that any unauthorized review, use, disclosure or distribution of this message is prohibited. Please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. Mycronic is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt.