22 #include "llvm/ADT/ImmutableMap.h"
23 using namespace clang;
29 enum Kind { NO_CHROOT, ROOT_CHANGED, JAIL_ENTERED };
31 bool isRootChanged(intptr_t k) {
return k == ROOT_CHANGED; }
41 class ChrootChecker :
public Checker<eval::Call, check::PreStmt<CallExpr> > {
44 mutable std::unique_ptr<BuiltinBug> BT_BreakJail;
47 ChrootChecker() : II_chroot(nullptr), II_chdir(nullptr) {}
49 static void *getTag() {
93 state = Mgr.
addGDM(state, ChrootChecker::getTag(), (
void*) ROOT_CHANGED);
102 const void *k = state->FindGDM(ChrootChecker::getTag());
112 if (
const StringRegion* StrRegion= dyn_cast<StringRegion>(R)) {
115 state = Mgr.
addGDM(state, ChrootChecker::getTag(),
116 (
void*) JAIL_ENTERED);
140 void *
const* k = C.
getState()->FindGDM(ChrootChecker::getTag());
142 if (isRootChanged((intptr_t) *k))
146 this,
"Break out of jail",
"No call of chdir(\"/\") immediately "
149 *BT_BreakJail, BT_BreakJail->getDescription(), N));
ProgramStateRef addGDM(ProgramStateRef St, void *Key, void *Data)
MemRegion - The root abstract class for all memory regions.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
IdentifierInfo * getIdentifier() const
ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generates a new transition in the program state graph (ExplodedGraph). Uses the default CheckerContex...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const FunctionDecl * getCalleeDecl(const CallExpr *CE) const
Get the declaration of the called function (path-sensitive).
const ProgramStateRef & getState() const
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ASTContext & getASTContext()
StringRef getString() const
const MemRegion * getAsRegion() const
StringRegion - Region associated with a StringLiteral.
const LocationContext * getLocationContext() const