...
| Code Block | ||
|---|---|---|
| ||
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
jmp_buf env;
int val;
void exit1(void) {
/* ... */
longjmp(env, 1);
}
int main(void) {
if (atexit(exit1) != 0) {
/* handle error */
}
/* ... */
if (setjmp(env) == 0) {
exit(0);
}
else {
return 0;
}
}
|
Compliant
...
Solution
Careful thought about program flow is the best prevention for an invalid call to longjmp(). After the exit function has been called, avoid using longjmp() where it will cause a function to terminate.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
ENV32-C | medium | likely | medium | P12 | L1 |
Automated Detection
Compass/ROSE can detect violations of this rule. In particular, it ensures that all functions registered with atexit() do not call functions such as exit().
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...