15 #include "../AllocationState.h"
25 using namespace clang;
29 class PutenvWithAutoChecker :
public Checker<check::PostCall> {
31 BugType BT{
this,
"'putenv' function should not be called with auto variables",
33 const CallDescription Putenv{
"putenv", 1};
36 void checkPostCall(
const CallEvent &Call, CheckerContext &C)
const;
40 void PutenvWithAutoChecker::checkPostCall(
const CallEvent &Call,
41 CheckerContext &C)
const {
42 if (!Putenv.matches(Call))
45 SVal ArgV =
Call.getArgSVal(0);
46 const Expr *ArgExpr =
Call.getArgExpr(0);
47 const MemSpaceRegion *MSR = ArgV.getAsRegion()->getMemorySpace();
49 if (!isa<StackSpaceRegion>(MSR))
52 StringRef ErrorMsg =
"The 'putenv' function should not be called with "
53 "arguments that have automatic storage";
54 ExplodedNode *N =
C.generateErrorNode();
55 auto Report = std::make_unique<PathSensitiveBugReport>(BT, ErrorMsg, N);
60 C.emitReport(std::move(Report));
63 void ento::registerPutenvWithAuto(CheckerManager &Mgr) {
64 Mgr.registerChecker<PutenvWithAutoChecker>();
67 bool ento::shouldRegisterPutenvWithAuto(
const CheckerManager &) {
return true; }