...
This noncompliant code example fails to reset the signal handler to its default behavior on those UNIX systems where handlers are persistent by default.
...
A C99-compliant solution to reset the handler on a UNIX system is to rebind the signal to the default handler in the first line of the handler itself. Windows, however, automatically resets handlers to their default behavior.
| Code Block | ||
|---|---|---|
| ||
void handler(int signum) {
#ifndef WINDOWS
if (signal(signum, SIG_DFL) == SIG_ERR) {
/* Handler error */
}
#endif
/* Handle signal */
}
|
With the compliant solution for UNIX, there is no race condition that can be exploited by an attacker in sending a second signal. And that This is because a second signal sent to the handler, before the latter calls signal(signum, SIG_DFL), will only cause the handler to restart and call signal() anyway.
...