CWE-244¶
Improper Clearing of Heap Memory Before Release (‘Heap Inspection’). [Improper-Control-Of-A-Resource-Through-Its-Lifetime]
Required inputs: IR
Demonstrative Examples
Example 1
The following code calls realloc() on a buffer containing sensitive data:
Example Language:C
cleartext_buffer = get_secret();...
cleartext_buffer = realloc(cleartext_buffer, 1024);
...
scrub_memory(cleartext_buffer, 1024);
There is an attempt to scrub the sensitive data from memory, but realloc() is used, so it could return a pointer to a different part of memory. The memory that was originally allocated for cleartext_buffer could still contain an uncleared copy of the data.
Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
clear_heap_before_release |
Memory with possible sensitive data not cleared before release. |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
clearing_functions¶
clearing_functions : list[str] = ['memset', 'std::memset']