...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdio.h>
int close_stdin(void) {
if (fclose(stdin) == 0) {
return -1;
}
else {
printf("stdin successfully closed.\n");
}
return 0;
} |
Compliant Solution
In this compliant solution, stdin is not used again after it is closed. This must remain true for the remainder of the program.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
FIO42FIO46-C | Medium | Unlikely | Medium | P4 | L3 |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
| CERT C++ Secure Coding Standard | FIO42-CPP. Ensure files are properly closed when they are no longer needed |
| CERT Oracle Secure Coding Standard for Java | FIO04-J. Release resources when they are no longer needed |
| ISO/IEC TS 17961 | Failing to close files or free dynamic memory when they are no longer needed [fileclose] |
| MITRE CWE | CWE-404, Improper resource shutdown or release |
Bibliography
| [IEEE Std 1003.1:2013] | XSH, System Interfaces, open |
| [ISO/IEC 9899:2011] | Subclause 7.21.3, "Files" Subclause 7.21.5.1, "The |
...