Wiki Markup |
---|
Dynamic memory management is a common source of programming flaws that can lead to security vulnerabilities. Decisions regarding how dynamic memory is allocated, used, and deallocated are the burden of the programmer. Poor memory management can lead to security issues, such as heap-buffer overflows, dangling pointers, and double-free issues \[[Seacord 2005a|AA. Bibliography#Seacord 05]\]. From the programmer's perspective, memory management involves allocating memory, reading and writing to memory, and deallocating memory. |
Allocating and freeing memory in different modules and levels of abstraction may make it difficult to determine when and if a block of memory has been freed, leading to programming defects, such as memory leaks, double-free vulnerabilities, accessing freed memory, or writing to freed or unallocated memory.
Wiki Markup |
---|
To avoid these situations, memory should be allocated and freed at the same level of abstraction and, ideally, in the same code module. This includes the use of the following memory allocation and deallocation functions described in C99, Section 7.20.3 \[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\]: |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelimes
CERT C++ Secure Coding Standard: MEM40-CPP. Allocate and free memory in the same module, at the same level of abstraction
Bibliography
unmigrated-wiki-markup
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 7.20.3, "Memory Management Functions" \[[
ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] TR 24772 "XYL Memory Leak"
MITRE CWE: CWE-416, "Use After Free"
MITRE CWE: CWE-415, "Double Free"
Bibliography
Wiki Markup |
---|
\[[MIT 2004|AA. Bibliography#MIT 04]\] \[[MIT 2004|AA. Bibliography#MIT 04]\] \[[MITRE 2007|AA. Bibliography#MITRE 07]\] [CWE ID 416|http://cwe.mitre.org/data/definitions/416.html], "Use After Free," and [CWE ID 415|http://cwe.mitre.org/data/definitions/415.html], "Double Free" \[[Plakosh 2005|AA. Bibliography#Plakosh 05]\] \[[Seacord 2005a|AA. Bibliography#Seacord 05]\] Chapter 4, "Dynamic Memory Management" |
...