From 5d324e509cb6147412a4484b23ac05940f04b434 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Wed, 18 Jan 2012 02:45:07 +0000 Subject: [analyzer] Taint: add taint propagation rules for string and memory copy functions. llvm-svn: 148370 --- clang/lib/StaticAnalyzer/Core/CheckerContext.cpp | 29 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Core/CheckerContext.cpp') diff --git a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp index 3737ca54672..cb272fb1c33 100644 --- a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -13,6 +13,8 @@ //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" +#include "clang/Basic/Builtins.h" + using namespace clang; using namespace ento; @@ -23,12 +25,31 @@ const FunctionDecl *CheckerContext::getCalleeDecl(const CallExpr *CE) const { return L.getAsFunctionDecl(); } -StringRef CheckerContext::getCalleeName(const CallExpr *CE) const { - const FunctionDecl *funDecl = getCalleeDecl(CE); - if (!funDecl) +StringRef CheckerContext::getCalleeName(const FunctionDecl *FunDecl) const { + if (!FunDecl) return StringRef(); - IdentifierInfo *funI = funDecl->getIdentifier(); + IdentifierInfo *funI = FunDecl->getIdentifier(); if (!funI) return StringRef(); return funI->getName(); } + + +bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, + StringRef Name){ + // To avoid false positives (Ex: finding user defined functions with + // similar names), only perform fuzzy name matching when it's a builtin. + // Using a string compare is slow, we might want to switch on BuiltinID here. + unsigned BId = FD->getBuiltinID(); + if (BId != 0) { + ASTContext &Context = getASTContext(); + StringRef BName = Context.BuiltinInfo.GetName(BId); + if (StringRef(BName).find(Name) != StringRef::npos) + return true; + } + + if (FD->isExternC() && FD->getIdentifier()->getName().equals(Name)) + return true; + + return false; +} -- cgit v1.2.3