According to Section the C Standard, subclause 7.14.1.1 (signals) of the C Standard 1 [ISO/IEC 9899:2011], returning from a SIGSEGV
, SIGILL
, or SIGFPE
signal handler is undefined behavior:
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include<signal#include <signal.h> #include<stddef#include <stddef.h> #include<stdlib#include <stdlib.h> volatile sig_atomic_t denom; void sighandle(int s){ /* Fix the offending volatile. */ if (denom == 0) { denom = 1; } /* Everything is ok */ return; } int main(int argc, char *argv[]){ int result = 0; if (argc < 2) { return 0; } denom = (intsig_atomic_t)strtol(argv[1], (char **)NULL, 10); signal(SIGFPE,(*sighandle)); result = 100/denom; return 0; } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include<signal#include <signal.h> #include<stddef#include <stddef.h> #include<stdlib#include <stdlib.h> volatile sig_atomic_t denom; void sighandle(int s){ /* No recoveryRecovery is impossible. */ abort(); } int main(int argc, char *argv[]){ int result = 0; if (argc < 2) { return 0; } denom = (intsig_atomic_t)strtol(argv[1], (char **)NULL, 10); signal(SIGFPE,(*sighandle)); result = 100/denom; return 0; } |
...
Code that attempts to handle SIGSEGV
, SIGILL
, or SIGFPE
signals is rare. However, code that does rely on handling these signals will usually require a redesign to fix the problem.
RecommendationRule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
SIG35-C | low | unlikely | high | P1 | L3 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Bibliography
[ISO/IEC 9899:2011] | Subclause 7.14.1.1, "The signal function" | Giri Mandalika | Mandalika's Scratchpad
...