FNH.MUSTFreeing non-heap memoryIf there is a non-heap memory deallocation-for instance, of static or stack memory-a program's memory management structures can be corrupted. The FNH.MUST checker flags situations in which an application frees memory that wasn't allocated using heap functions such as malloc(), calloc(), or realloc(). Vulnerability and riskFreeing non-heap memory can cause corruption of a program's memory, resulting in program crash, and possibly creating a vulnerability that an attacker can exploit. For instance, a malicious user can use free() to access memory locations, modifying data or executing unauthorized commands or code. Mitigation and preventionTo avoid freeing non-heap memory, make sure that you:
Vulnerable code example1 class A { 2 public: 3 void foo(); 4 }; 5 6 void A::foo() 7 { 8 int localArray[2] = { 11, 22 }; 9 delete[] localArray; 10 } Klocwork produces a non-heap memory deallocation report, indicating that 'localArray' points to a non-heap memory when it is passed to delete[]. Freeing non-heap memory can cause an application to crash, and possibly result in vulnerability to attack. Related checkersExternal guidanceExtensionThis checker can be extended through the Klocwork knowledge base. See Tuning C/C++ analysis for more information. |