[Top][All Lists]

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

[PATCH] Defer SIGCHLD trap handler when waitchld is called from within t

From: Siddhesh Poyarekar
Subject: [PATCH] Defer SIGCHLD trap handler when waitchld is called from within the signal handler
Date: Tue, 6 Mar 2012 18:29:47 +0530
User-agent: Mutt/1.5.21 (2010-09-15)

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/\
locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib 
-fexceptions -fstack-pr\
otector --param=ssp-buffer-size=4  -m64 -mtune=generic
uname output: Linux hostname.removed 3.1.6-1.fc16.x86_64 #1 SMP Wed Dec 21 
22:41:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 4.2
Patch Level: 20
Release Status: release


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.


$ cat > foo.sh

check_stop_child_trap() {
        echo "child died!"

do_something() {
        while true; do
                true &

trap check_stop_child_trap SIGCHLD
do_something &


$ bash
$ . foo.sh


The above may either hang or result in a segmentation fault.


The attached patch fixes this by deferring execution of the trap
handler by adding it to pending_sigs.


Attachment: bash-defer-sigchld-trap.patch
Description: Text document

reply via email to

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