...
Code Block |
---|
#include <stdio.h> #include <signal.h> volatile sig_atomic_t e_flag = 0; void handler(int signum) { e_flag = 1; } int main(void) { signal(SIGINT, handler); while (!e_flag) {} puts("Escaped from first while ()"); e_flag = 0; while (!e_flag) {} puts("Escaped from second while ()"); return 0; } |
*nix systems automatically reinstall signal handlers upon handler execution. For example, when compiled with gcc 3.4.4 and executed under Red Hat Linux, the SIGINT
is captured both times by handler
.
Code Block |
---|
% ./SIG01-A ^C Escaped from first while () ^C Escaped from second while () % |
However, under Windows systems signal handlers are not automatically reinstalled. For example, when compiled with Microsoft Visual Studio 2005 version 8.0, only the first SIGINT
is captured by handler
.
Code Block |
---|
> SIG01-A.exe
^C
Escaped from first while ()
^C
>
|
The second SIGINT
executes the default action, which is to terminate program execution.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
SIG01-A | 1 (highlow) | 1 (likelyunlikely) | 3 (low) | P3 | L3 |
References
Wiki Markup |
---|
\[[ISO/IEC 9899-1999TR2|AA. C References#ISO/IEC 9899-1999]\] Section 7.14.1.1, "The {{signal}} function" |