Calling free()
on a block of dynamic memory marks that memory for deallocation. Once deallocated, the block of memory is made available for future allocation. However, the data stored in the block of memory to be recycled may be preserved. If this memory block contains sensitive information, that information may be unintentionally exposed.
This type of defect can lead to information leakage , for instance, as is described in Rule: [MEM33-C. Do not assume memory allocation routines initialize memory]. Other attacks, such as _heap inspection_ \[[vulncat|http://vulncat.fortifysoftware.com/2/HI.html] and [samate|http://samate.nist.gov/docs/SAMATE_source_code_analysis_tool_spec_09_15_06.pdf]\] can also occur. To prevent other information leakage and heap inspection it is necessary to clear sensitive information from dynamically allocated . Attackers may also be able to leverage this defect to retreive sensitive information using techniques, such as heap inspection. Wiki Markup
To prevent information leakage it is necessary to clear sensitive information from dynamically allocated buffers before they are buffers before they are freed.
Non-Compliant Code Example 1
...
Non-Compliant Code Example 2
Wiki Markup |
---|
Using {{realloc()}} to resize dynamic memory may inadvertently expose sensitive information, or allow heap inspection as is described in Fortify's Taxonomy of Software Security Errors \[[vulncat|http://vulncat.fortifysoftware.com/2/HI.html]\] and NIST's Source Code Analysis Tool Functional Specification \[[SAMATE]\]. {{realloc()}} may allocate a new, larger block of memory, copy the contents, of {{buffer}} to this new block, {{free()}} the original block, and assign the newly allocated block to {{buffer}}. However, the contents of the original block may remain in heap memory after being marked for deallocation. |
Code Block | ||
---|---|---|
| ||
... buffer = realloc(buffer,new_size); ... |
...