Skip to content

[analyzer] Use explicit call description mode (easy cases) #88879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ class CastValueChecker : public Checker<check::DeadSymbols, eval::Call> {

private:
// These are known in the LLVM project. The pairs are in the following form:
// {{{namespace, call}, argument-count}, {callback, kind}}
// {{match-mode, {namespace, call}, argument-count}, {callback, kind}}
const CallDescriptionMap<std::pair<CastCheck, CallKind>> CDM = {
{{{"llvm", "cast"}, 1},
{{CDM::SimpleFunc, {"llvm", "cast"}, 1},
{&CastValueChecker::evalCast, CallKind::Function}},
{{{"llvm", "dyn_cast"}, 1},
{{CDM::SimpleFunc, {"llvm", "dyn_cast"}, 1},
{&CastValueChecker::evalDynCast, CallKind::Function}},
{{{"llvm", "cast_or_null"}, 1},
{{CDM::SimpleFunc, {"llvm", "cast_or_null"}, 1},
{&CastValueChecker::evalCastOrNull, CallKind::Function}},
{{{"llvm", "dyn_cast_or_null"}, 1},
{{CDM::SimpleFunc, {"llvm", "dyn_cast_or_null"}, 1},
{&CastValueChecker::evalDynCastOrNull, CallKind::Function}},
{{{"clang", "castAs"}, 0},
{{CDM::CXXMethod, {"clang", "castAs"}, 0},
{&CastValueChecker::evalCastAs, CallKind::Method}},
{{{"clang", "getAs"}, 0},
{{CDM::CXXMethod, {"clang", "getAs"}, 0},
{&CastValueChecker::evalGetAs, CallKind::Method}},
{{{"llvm", "isa"}, 1},
{{CDM::SimpleFunc, {"llvm", "isa"}, 1},
{&CastValueChecker::evalIsa, CallKind::InstanceOf}},
{{{"llvm", "isa_and_nonnull"}, 1},
{{CDM::SimpleFunc, {"llvm", "isa_and_nonnull"}, 1},
{&CastValueChecker::evalIsaAndNonNull, CallKind::InstanceOf}}};

void evalCast(const CallEvent &Call, DefinedOrUnknownSVal DV,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ChrootChecker : public Checker<eval::Call, check::PreCall> {
// This bug refers to possibly break out of a chroot() jail.
const BugType BT_BreakJail{this, "Break out of jail"};

const CallDescription Chroot{{"chroot"}, 1}, Chdir{{"chdir"}, 1};
const CallDescription Chroot{CDM::CLibrary, {"chroot"}, 1},
Chdir{CDM::CLibrary, {"chdir"}, 1};

public:
ChrootChecker() {}
Expand Down
12 changes: 7 additions & 5 deletions clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ class ErrnoTesterChecker : public Checker<eval::Call> {

using EvalFn = std::function<void(CheckerContext &, const CallEvent &)>;
const CallDescriptionMap<EvalFn> TestCalls{
{{{"ErrnoTesterChecker_setErrno"}, 1}, &ErrnoTesterChecker::evalSetErrno},
{{{"ErrnoTesterChecker_getErrno"}, 0}, &ErrnoTesterChecker::evalGetErrno},
{{{"ErrnoTesterChecker_setErrnoIfError"}, 0},
{{CDM::SimpleFunc, {"ErrnoTesterChecker_setErrno"}, 1},
&ErrnoTesterChecker::evalSetErrno},
{{CDM::SimpleFunc, {"ErrnoTesterChecker_getErrno"}, 0},
&ErrnoTesterChecker::evalGetErrno},
{{CDM::SimpleFunc, {"ErrnoTesterChecker_setErrnoIfError"}, 0},
&ErrnoTesterChecker::evalSetErrnoIfError},
{{{"ErrnoTesterChecker_setErrnoIfErrorRange"}, 0},
{{CDM::SimpleFunc, {"ErrnoTesterChecker_setErrnoIfErrorRange"}, 0},
&ErrnoTesterChecker::evalSetErrnoIfErrorRange},
{{{"ErrnoTesterChecker_setErrnoCheckState"}, 0},
{{CDM::SimpleFunc, {"ErrnoTesterChecker_setErrnoCheckState"}, 0},
&ErrnoTesterChecker::evalSetErrnoCheckState}};
};

Expand Down
5 changes: 2 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ using namespace ento;

namespace {
class MmapWriteExecChecker : public Checker<check::PreCall> {
CallDescription MmapFn;
CallDescription MprotectFn;
CallDescription MmapFn{CDM::CLibrary, {"mmap"}, 6};
CallDescription MprotectFn{CDM::CLibrary, {"mprotect"}, 3};
static int ProtWrite;
static int ProtExec;
static int ProtRead;
const BugType BT{this, "W^X check fails, Write Exec prot flags set",
"Security"};

public:
MmapWriteExecChecker() : MmapFn({"mmap"}, 6), MprotectFn({"mprotect"}, 3) {}
void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
int ProtExecOv;
int ProtReadOv;
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/StaticAnalyzer/Checkers/StdVariantChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ static llvm::StringRef indefiniteArticleBasedOnVowel(char a) {

class StdVariantChecker : public Checker<eval::Call, check::RegionChanges> {
// Call descriptors to find relevant calls
CallDescription VariantConstructor{{"std", "variant", "variant"}};
CallDescription VariantAssignmentOperator{{"std", "variant", "operator="}};
CallDescription StdGet{{"std", "get"}, 1, 1};
CallDescription VariantConstructor{CDM::CXXMethod,
{"std", "variant", "variant"}};
CallDescription VariantAssignmentOperator{CDM::CXXMethod,
{"std", "variant", "operator="}};
CallDescription StdGet{CDM::SimpleFunc, {"std", "get"}, 1, 1};

BugType BadVariantType{this, "BadVariantType", "BadVariantType"};

Expand Down Expand Up @@ -295,4 +297,4 @@ bool clang::ento::shouldRegisterStdVariantChecker(

void clang::ento::registerStdVariantChecker(clang::ento::CheckerManager &mgr) {
mgr.registerChecker<StdVariantChecker>();
}
}
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Checkers/StringChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StringChecker : public Checker<check::PreCall> {
mutable const FunctionDecl *StringConstCharPtrCtor = nullptr;
mutable CanQualType SizeTypeTy;
const CallDescription TwoParamStdStringCtor = {
{"std", "basic_string", "basic_string"}, 2, 2};
CDM::CXXMethod, {"std", "basic_string", "basic_string"}, 2, 2};

bool isCharToStringCtor(const CallEvent &Call, const ASTContext &ACtx) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PutenvWithAutoChecker : public Checker<check::PostCall> {
private:
BugType BT{this, "'putenv' function should not be called with auto variables",
categories::SecurityError};
const CallDescription Putenv{{"putenv"}, 1};
const CallDescription Putenv{CDM::CLibrary, {"putenv"}, 1};

public:
void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
Expand Down