...
Do not explicitly or implicitly call std::quick_exit()
, std::abort()
, or std::_Exit()
. When the default terminate_handler
is installed or the current terminate_handler
responds by calling std::abort()
or std::_Exit()
, do not explicitly or implicitly call std::terminate()
. Abnormal process termination is the typical vector for denial-of-service attacks.
The std::exit()
function is more complex. The C++ Standard, [basic.start.main], paragraph 4, states:
Terminating the program without leaving the current block (e.g., by calling the function std::exit(int) (17.5)) does not destroy any objects with automatic storage duration (11.4.6). If std::exit is called to end a program during the destruction of an object with static or thread storage duration, the program has undefined behavior.
You may call It is acceptable to call a termination function that safely executes destructors and properly cleans up resources, such as std::exit()
only in a program that has not yet initialized any objects with automatic storage duration.
Noncompliant Code Example
...
Allowing the application to abnormally terminate can lead to resources not being freed, closed, and so on. It is frequently a vector for denial-of-service attacks.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
ERR50-CPP | Low | Probable | Medium | P4 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Astrée |
| stdlib-use | Partially checked | ||||||
CodeSonar |
| BADFUNC.ABORT | Use of abort | ||||||
Helix QAC |
| C++5014 | |||||||
Klocwork |
| MISRA.TERMINATE CERT. |
ERR.ABRUPT_TERM | |||||||||
LDRA tool suite |
| 122 S | Enhanced Enforcement |
Parasoft C/C++test |
|
5014
| CERT_CPP-ERR50-a | The execution of a function registered with 'std::atexit()' or 'std::at_quick_exit()' should not exit via an exception | |||||||
Polyspace Bug Finder |
| CERT C++: ERR50-CPP | Checks for implicit call to terminate() function (rule partially covered) | ||||||
PVS-Studio |
| V667, V2014 | |||||||
RuleChecker |
| stdlib-use | Partially checked |
SonarQube C/C++ Plugin |
| S990 |
Related Vulnerabilities
Search for other vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
SEI CERT C++ Coding Standard | ERR51-CPP. Handle all exceptions |
MITRE CWE | CWE-754, Improper Check for Unusual or Exceptional Conditions |
Bibliography
[ISO/IEC 9899-2011] | Subclause 7.20.4.1, "The abort Function"Subclause 7.20.4.4, "The _Exit Function" |
[ISO/IEC 14882-2014] | Subclause 15.5.1, "The |
[MISRA 2008] | Rule 15-3-2 (Advisory) Rule 15-3-4 (Required) |
...
...