FUM.GEN.MUSTFreeing unallocated memoryIf unallocated memory is freed, results can be unpredictable. The FUM.GEN.MUST checker finds deallocation functions that are invoked with an uninitialized pointer. Vulnerability and riskWhen free() is called on an invalid pointer, it can cause corruption of a program's memory, resulting in program crash, and possibly creating a vulnerability that an attacker can exploit. Mitigation and preventionTo avoid freeing non-heap memory, make sure that you:
Vulnerable code example1 typedef struct list { 2 char * next; 3 } list; 4 typedef struct z { 5 list l; 6 } z; 7 8 void a6(){ // 8923 9 z * x = malloc(sizeof(z)); 10 if (!x) return; 11 x->l.next=1; 12 free(x->l.next); 13 } Klocwork produces an issue report at line 12 indicating that unallocated memory referenced by 'x->l.next' and assigned on line 11 was freed at line 12. Freeing unallocated 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. |