You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clang Static Analyzer's MallocChecker currently fails to detect use-after-free when the memory is accessed via the address of a field inside a freed structure.
For example, the following use-after-free goes undetected:
#include<stdlib.h>structObj {
intfield;
};
voiduse(void*);
voidtest() {
structObj*o=malloc(sizeof(structObj));
free(o);
use(&o->field); // ⚠️ No warning reported by CSA (MallocChecker)
}
In this example, the heap memory pointed to by o has been freed, yet &o->field is passed to a function. This is a classic use-after-free bug, but MallocChecker does not currently report it.
Root Cause
In MallocChecker.cpp, argument checking currently relies on:
SymbolRef Sym = ArgSVal.getAsSymbol();
This fails for field address expressions like &ptr->field, because such expressions produce a MemRegionVal, and getAsSymbol() does not extract the base symbol in those cases.