Segmentation fault with associative arrays

Bug #928900 reported by John Valko
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

If we write code like:

function foo {
    declare -A hash
    declare hash[foo]=bar #bash crashes here
}

Bash crashes when calling this function. The same exact code works as expected if it's not in a shell function.

Additional details:

$ lsb_release -rd
Description: Ubuntu 11.10
Release: 11.10
$ apt-cache policy bash
bash:
  Installed: 4.2-0ubuntu4
  Candidate: 4.2-0ubuntu4
  Version table:
 *** 4.2-0ubuntu4 0
        500 http://us.archive.ubuntu.com/ubuntu/ oneiric/main amd64 Packages
        100 /var/lib/dpkg/status

Daniel Manrique (roadmr)
Changed in bash (Ubuntu):
status: New → Confirmed
Revision history for this message
Daniel Manrique (roadmr) wrote :

Confirmed with importance: Medium as it is "A bug that has a moderate impact on a core application. "

This script will reproduce (I changed the associative array's key to "baz" to avoid confusion with the function name (foo)).

TEST CASE:

Run the following BASH script:

#!/bin/bash
function foo {
    declare -A hash
    declare hash[baz]=bar #bash crashes here
}

foo

Expected result:
nothing, but not a crash either

Actual result:
Segmentation fault

Revision history for this message
John Valko (jvalko-gmail) wrote :

I'm not sure that "nothing" is the expected result -- the expected result is that it should add a new key/value to the associative array:

$ declare -A hash
$ declare hash[baz]=bar
$ declare -p hash
declare -A hash='([baz]="bar" )'

(output from running directly, rather than as a shell function).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.