...
| Code Block | ||
|---|---|---|
| ||
#include <signal.h><signal.h> sig_atomic_t i; void handler(int signum) { i = 0; } int main(void) { i = 1; signal(SIGINT, handler); while (i) { /* do something */ } return 0; } |
...
| Code Block | ||
|---|---|---|
| ||
#include <signal.h><signal.h> sig_atomic_t i; void handler(int signum) { i = 0; } int main(void) { i = 1; signal(SIGINT, handler); while (*(volatile sig_atomic_t *)&i) { /* do something */ } return 0; } |
...
| Code Block | ||
|---|---|---|
| ||
#include <signal.h><signal.h> volatile sig_atomic_t i; void handler(int signum) { i = 0; } int main(void) { i = 1; signal(SIGINT, handler); while (i) { /* do something */ } return 0; } |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
This rule appears in the C++ Secure Coding Standard as DCL34-CPP. Use volatile for data that cannot be cached.
References
| Wiki Markup |
|---|
\[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.7.3, ""Type qualifiers,"" and Section 7.14, ""Signal handling <signal.h>"<signal.h>" \[[ISO/IEC 03|AA. C References#ISO/IEC 03]\] Section 6.7.3, ""Type qualifiers"" \[[Sun 05|AA. C References#Sun 05]\] [Chapter 6, ""Transitioning to ISO C""|http://docs.sun.com/source/819-3688/tguide.html#pgfId-997898] |
...
DCL33-C. Ensure that restrict-qualified source and destination pointers in function arguments do not reference overlapping objects 02. Declarations and Initialization (DCL) DCL35-C. Do not invoke a function using a type that does not match the function definition