...
| Code Block | ||
|---|---|---|
| ||
#include <stdio.h>
#include <stdlib.h>
#define exitearly 1
void exit1(void) {
puts("Exit second.\n");
}
void exit2 (void) {
puts("Exit first.\n");
if (exitearly) {
exit(1);
}
}
int main (void) {
if (expr) {
atexit (exit1);
atexit (exit2);
puts("In main\n");
exit(1);
exit(1);
}
else {
exit2();
}
return 0;
}
|
Compliant Code
...
| Code Block | ||
|---|---|---|
| ||
#include <stdio.h>
#include <stdlib.h>
#define exitearly 1
void exit1(void)
{
printf("Exit second.\n");
}
void exit2 (void)
{
printf("Exit first.\n");
if (exitearly)
{
_exit(1);
}
}
int main (void) {
if (expr) {
atexit (exit1);
atexit (exit2);
printf("In main\n"exit(1);
exit(1}
else {
exit2();
}
return 0;
}
|
All functions registered by the atexit() function are called, in the reverse order of their registration.
Risk Assessment
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
MSC31-C | 1 (low) | 1 (unlikely) | 3(low) | P6 | L2 |
...