bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] Defer SIGCHLD trap handler when waitchld is called from with


From: Chet Ramey
Subject: Re: [PATCH] Defer SIGCHLD trap handler when waitchld is called from within the signal handler
Date: Sat, 10 Mar 2012 15:50:39 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 3/6/12 7:59 AM, Siddhesh Poyarekar wrote:

> Bash Version: 4.2
> Patch Level: 20
> Release Status: release
> 
> Description:
> 
> When a SIGCHLD is received in job control mode and a handler for the
> signal is installed, bash calls the trap handler within the signal
> handler itself. This is unsafe because the trap handler function
> run_sigchld_trap() uses the glibc malloc functions quite extensively
> (within the function itself and also the function it calls, i.e.
> parse_and_execute() ). This results in a deadlock and sometimes even a
> segmentation fault due to memory corruption.
> 
> Repeat-By:
> 
> $ cat > foo.sh
> #!/bin/sh
> 
> check_stop_child_trap() {
>         echo "child died!"
> }
> 
> do_something() {
>         while true; do
>                 true &
>         done
> }
> 
> trap check_stop_child_trap SIGCHLD
> do_something &
> do_something
> 
> ^d
> 
> $ bash
> $ . foo.sh
> 
> ------------------
> 
> The above may either hang or result in a segmentation fault.
> 
> Fix:
> 
> The attached patch fixes this by deferring execution of the trap
> handler by adding it to pending_sigs.

Good catch.  Thanks for the report.  The fix will be in the next release
of bash.

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



reply via email to

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