...
In this noncompliant code example, the signal handler handler() is bound to signum.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
void handler(int signum) {
if (signal(signum, handler) == SIG_ERR) {
/* Handle error */
}
/* Handle signal */
}
/* ... */
if (signal(SIGUSR1, handler) == SIG_ERR) {
/* Handle error */
}
|
...
For persistent platforms, calling the signal() function from within the signal handler is unnecessary.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
void handler(int signum) {
/* Handle signal */
}
/* ... */
if (signal(SIGUSR1, handler) == SIG_ERR) {
/* Handle error */
}
|
...
The following code example resets a signal handler to the system's default behavior.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
void handler(int signum) {
#ifndef WINDOWS
if (signal(signum, SIG_DFL) == SIG_ERR) {
/* Handle error */
}
#endif
/* Handle signal */
}
/* ... */
if (signal(SIGUSR1, handler) == SIG_ERR) {
/* Handle error */
}
|
...
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Compass/ROSE | Can detect violations of this rule. However, false positives may occur on systems with persistent handlers. | ||||||||
| PRQA QA-C |
| Warncall -wc signal | Partially implemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...