25class StoreToImmutableChecker :
public Checker<check::Bind> {
26 const BugType BT{
this,
"Write to immutable memory",
"CERT Environment (ENV)"};
35 if (isa<GlobalImmutableSpaceRegion>(MR))
39 if (
const auto *TR = dyn_cast<TypedRegion>(MR)) {
40 QualType LocationType = TR->getDesugaredLocationType(
C.getASTContext());
48 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR)) {
49 QualType PointeeType = SR->getPointeeStaticType();
65 if (
auto *SR = dyn_cast<SubRegion>(MR))
66 MR = SR->getSuperRegion();
75 if (
const auto *DR = dyn_cast<DeclRegion>(MR)) {
81 if (
auto *SR = dyn_cast<SubRegion>(MR))
82 MR = SR->getSuperRegion();
88void StoreToImmutableChecker::checkBind(
SVal Loc,
SVal Val,
const Stmt *S,
103 const bool IsGlobalImmutableSpace = isa<GlobalImmutableSpaceRegion>(MS);
106 if (!IsGlobalImmutableSpace && !InnermostConstRegion)
110 if (IsGlobalImmutableSpace)
111 WarningMessage +=
" in global read-only storage";
118 auto R = std::make_unique<PathSensitiveBugReport>(BT, WarningMessage, N);
119 R->addRange(S->getSourceRange());
126 const char *NoteMessage =
127 (DR != MR) ?
"Enclosing memory region is declared as immutable here"
128 :
"Memory region is declared as immutable here";
130 DR->
getDecl(),
C.getSourceManager()));
136 C.emitReport(std::move(R));
143bool ento::shouldRegisterStoreToImmutableChecker(
const CheckerManager &mgr) {
static const MemRegion * getInnermostConstRegion(const MemRegion *MR, CheckerContext &C)
static const DeclRegion * getInnermostEnclosingConstDeclRegion(const MemRegion *MR, CheckerContext &C)
static bool isEffectivelyConstRegion(const MemRegion *MR, CheckerContext &C)
A (possibly-)qualified type.
bool isConstQualified() const
Determine whether this type is const-qualified.
Stmt - This represents one statement.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isPointerOrReferenceType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
virtual const ValueDecl * getDecl() const =0
MemRegion - The root abstract class for all memory regions.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion * getMemorySpace(ProgramStateRef State) const
Returns the most specific memory space for this memory region in the given ProgramStateRef.
MemSpaceRegion - A memory region that represents a "memory space"; for example, the set of global var...
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
const MemRegion * getAsRegion() const
The JSON file list parser is used to communicate input to InstallAPI.