diff options
author | Anna Zaks <ganna@apple.com> | 2011-12-14 00:55:58 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2011-12-14 00:55:58 +0000 |
commit | e55a22b917327651178ddea36b3615f579681eea (patch) | |
tree | 6d0b7793bc406a4d9e3aad16dfeeaac446648fe3 | |
parent | 9f6d068b29ea2f6276f1105c71d9e768201f2b88 (diff) |
[analyzer] Mark getenv output as tainted.
Also, allow adding taint to a region (not only a symbolic value).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146532 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp | 1 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/ProgramState.cpp | 11 | ||||
-rw-r--r-- | test/Analysis/taint-tester.c | 10 |
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp b/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp index 76405a2db2..dcf7694464 100644 --- a/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp @@ -63,6 +63,7 @@ void GenericTaintChecker::checkPostStmt(const CallExpr *CE, FnCheck evalFunction = llvm::StringSwitch<FnCheck>(Name) .Case("scanf", &GenericTaintChecker::processScanf) .Case("getchar", &GenericTaintChecker::processRetTaint) + .Case("getenv", &GenericTaintChecker::processRetTaint) .Default(NULL); // If the callee isn't defined, it is not of security concern. diff --git a/lib/StaticAnalyzer/Core/ProgramState.cpp b/lib/StaticAnalyzer/Core/ProgramState.cpp index 43b0b3e942..af038c6f0f 100644 --- a/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -654,8 +654,15 @@ bool ProgramState::scanReachableSymbols(const MemRegion * const *I, const ProgramState* ProgramState::addTaint(const Stmt *S, TaintTagType Kind) const { SymbolRef Sym = getSVal(S).getAsSymbol(); - assert(Sym && "Cannot add taint to statements whose value is not a symbol"); - return addTaint(Sym, Kind); + if (Sym) + return addTaint(Sym, Kind); + + const MemRegion *R = getSVal(S).getAsRegion(); + if (const SymbolicRegion *SR = dyn_cast_or_null<SymbolicRegion>(R)) + return addTaint(SR->getSymbol(), Kind); + + // Cannot add taint, so just return the state. + return this; } const ProgramState* ProgramState::addTaint(SymbolRef Sym, diff --git a/test/Analysis/taint-tester.c b/test/Analysis/taint-tester.c index da1ff024d1..7e2d771758 100644 --- a/test/Analysis/taint-tester.c +++ b/test/Analysis/taint-tester.c @@ -70,3 +70,13 @@ void BitwiseOp(int in, char inn) { m = inn; int mm = m; // expected-warning {{tainted}} } + +// Test getenv. +char *getenv(const char *name); +void getenvTest(char *home) { + home = getenv("HOME"); // expected-warning 2 {{tainted}} + if (home != 0) { // expected-warning 2 {{tainted}} + char d = home[0]; // expected-warning 2 {{tainted}} + } +} + |