#include "Yaml.h"
#include "clang/AST/Attr.h"
#include "clang/Basic/Builtins.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Checkers/Taint.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/YAMLTraits.h"
#include <limits>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#define DEBUG_TYPE …
usingnamespaceclang;
usingnamespaceento;
usingnamespacetaint;
ImmutableSet;
namespace {
class GenericTaintChecker;
constexpr llvm::StringLiteral MsgUncontrolledFormatString = …;
constexpr llvm::StringLiteral MsgSanitizeSystemArgs = …;
constexpr llvm::StringLiteral MsgCustomSink = …;
ArgIdxTy;
ArgVecTy;
constexpr ArgIdxTy ReturnValueIndex{ … };
static ArgIdxTy fromArgumentCount(unsigned Count) { … }
bool isStdin(SVal Val, const ASTContext &ACtx) { … }
SVal getPointeeOf(ProgramStateRef State, Loc LValue) { … }
std::optional<SVal> getPointeeOf(ProgramStateRef State, SVal Arg) { … }
std::optional<SVal> getTaintedPointeeOrPointer(ProgramStateRef State,
SVal Arg) { … }
bool isTaintedOrPointsToTainted(ProgramStateRef State, SVal ExprSVal) { … }
const NoteTag *taintOriginTrackerTag(CheckerContext &C,
std::vector<SymbolRef> TaintedSymbols,
std::vector<ArgIdxTy> TaintedArgs,
const LocationContext *CallLocation) { … }
const NoteTag *taintPropagationExplainerTag(
CheckerContext &C, std::vector<SymbolRef> TaintedSymbols,
std::vector<ArgIdxTy> TaintedArgs, const LocationContext *CallLocation) { … }
class ArgSet { … };
class GenericTaintRule { … };
RuleLookupTy;
struct TaintConfiguration { … };
struct GenericTaintRuleParser { … };
class GenericTaintChecker : public Checker<check::PreCall, check::PostCall> { … };
}
LLVM_YAML_IS_SEQUENCE_VECTOR(TaintConfiguration::Sink)
LLVM_YAML_IS_SEQUENCE_VECTOR(TaintConfiguration::Filter)
LLVM_YAML_IS_SEQUENCE_VECTOR(TaintConfiguration::Propagation)
namespace llvm {
namespace yaml {
template <> struct MappingTraits<TaintConfiguration> { … };
template <> struct MappingTraits<TaintConfiguration::Sink> { … };
template <> struct MappingTraits<TaintConfiguration::Filter> { … };
template <> struct MappingTraits<TaintConfiguration::Propagation> { … };
template <> struct ScalarEnumerationTraits<TaintConfiguration::VariadicType> { … };
}
}
REGISTER_MAP_WITH_PROGRAMSTATE(…) …
REGISTER_SET_FACTORY_WITH_PROGRAMSTATE(…)
void GenericTaintRuleParser::validateArgVector(const std::string &Option,
const ArgVecTy &Args) const { … }
template <typename Config>
GenericTaintRuleParser::NamePartsTy
GenericTaintRuleParser::parseNameParts(const Config &C) { … }
template <typename Config>
void GenericTaintRuleParser::consumeRulesFromConfig(const Config &C,
GenericTaintRule &&Rule,
RulesContTy &Rules) { … }
void GenericTaintRuleParser::parseConfig(const std::string &Option,
TaintConfiguration::Sink &&S,
RulesContTy &Rules) const { … }
void GenericTaintRuleParser::parseConfig(const std::string &Option,
TaintConfiguration::Filter &&S,
RulesContTy &Rules) const { … }
void GenericTaintRuleParser::parseConfig(const std::string &Option,
TaintConfiguration::Propagation &&P,
RulesContTy &Rules) const { … }
GenericTaintRuleParser::RulesContTy
GenericTaintRuleParser::parseConfiguration(const std::string &Option,
TaintConfiguration &&Config) const { … }
void GenericTaintChecker::initTaintRules(CheckerContext &C) const { … }
void GenericTaintChecker::checkPreCall(const CallEvent &Call,
CheckerContext &C) const { … }
void GenericTaintChecker::checkPostCall(const CallEvent &Call,
CheckerContext &C) const { … }
void GenericTaintChecker::printState(raw_ostream &Out, ProgramStateRef State,
const char *NL, const char *Sep) const { … }
void GenericTaintRule::process(const GenericTaintChecker &Checker,
const CallEvent &Call, CheckerContext &C) const { … }
bool GenericTaintRule::UntrustedEnv(CheckerContext &C) { … }
bool GenericTaintChecker::generateReportIfTainted(const Expr *E, StringRef Msg,
CheckerContext &C) const { … }
static bool getPrintfFormatArgumentNum(const CallEvent &Call,
const CheckerContext &C,
ArgIdxTy &ArgNum) { … }
bool GenericTaintChecker::checkUncontrolledFormatString(
const CallEvent &Call, CheckerContext &C) const { … }
void GenericTaintChecker::taintUnsafeSocketProtocol(const CallEvent &Call,
CheckerContext &C) const { … }
void ento::registerTaintPropagationChecker(CheckerManager &Mgr) { … }
bool ento::shouldRegisterTaintPropagationChecker(const CheckerManager &mgr) { … }
void ento::registerGenericTaintChecker(CheckerManager &Mgr) { … }
bool ento::shouldRegisterGenericTaintChecker(const CheckerManager &mgr) { … }