mirror of
https://github.com/mirror/wget.git
synced 2025-01-19 00:30:22 +08:00
Fix signal race condition
The signal handler for SIGALRM calls longjmp, but the handler is installed before the jump target has been initialized. If another process sends SIGALRM right between handler installation and target initialization, the jump leads to undefined behavior. This can easily be fixed by moving the signal handler installation into the "SETJMP == 0" conditional block, which means that the target has just been initialized. * src/utils.c: call signal after SETJMP. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
This commit is contained in:
parent
0fe79eeacb
commit
a9d49e5b15
@ -2045,13 +2045,16 @@ run_with_timeout (double timeout, void (*fun) (void *), void *arg)
|
||||
return false;
|
||||
}
|
||||
|
||||
signal (SIGALRM, abort_run_with_timeout);
|
||||
if (SETJMP (run_with_timeout_env) != 0)
|
||||
{
|
||||
/* Longjumped out of FUN with a timeout. */
|
||||
signal (SIGALRM, SIG_DFL);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
signal (SIGALRM, abort_run_with_timeout);
|
||||
}
|
||||
alarm_set (timeout);
|
||||
fun (arg);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user