In this noncompliant example, the C standard library functions
free() are called from the signal handler via the function
log_message(). Neither function is asynchronous-safe.
The following table from the POSIX standard [IEEE Std 1003.1:2013] defines a set of functions that are asynchronous-signal-safe. Applications may invoke these functions, without restriction, from a signal handler.
All functions not listed in this table are considered to be unsafe with respect to signals. In the presence of signals, all POSIX functions behave as defined when called from or interrupted by a signal handler, with a single exception: when a signal interrupts an unsafe function and the signal handler calls an unsafe function, the behavior is undefined.
|Axivion Bauhaus Suite|
|Can detect violations of the rule for single-file programs|
|LDRA tool suite|
88 D, 89 D
Properly define signal handlers
Checks for function called from signal handler not asynchronous-safe (rule fully covered)
For an overview of software vulnerabilities resulting from improper signal handling, see Michal Zalewski's paper "Delivering Signals for Fun and Profit" [Zalewski 2001].
Key here (explains table format and definitions)
|ISO/IEC TS 17961:2013||Calling functions in the C Standard Library other than |
|Prior to 2018-01-12: CERT: Unspecified Relationship|
|CWE 2.11||CWE-479, Signal Handler Use of a Non-reentrant Function||2017-07-10: CERT: Exact|
|[C99 Rationale 2003]||Subclause 5.2.3, "Signals and Interrupts"|
Subclause 22.214.171.124, "The
|[Dowd 2006]||Chapter 13, "Synchronization and State"|
|[IEEE Std 1003.1:2013]||XSH, System Interfaces, |
XSH, System Interfaces,
|[ISO/IEC 9899:2011]||126.96.36.199, "The |
|[Zalewski 2001]||"Delivering Signals for Fun and Profit"|
adjust column widths