FNH.MIGHTFreeing non-heap memory possibleIf 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.MIGHT checker flags situations in which an application might free 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(bool); 4 }; 5 6 void A::foo(bool heap) 7 { 8 int localArray[2] = {11,22}; 9 int *p = localArray; 10 if (heap) { 11 p = new int[2]; 12 } 13 delete[] p; 14 } Klocwork produces a non-heap memory deallocation report, indicating that 'p' might point to 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. |