Commit Graph

652 Commits

Author SHA1 Message Date
Anna Zaks 099fe3fb28 [analyzer] Treat stdin as a source of taint.
Some of the test cases do not currently work because the analyzer core
does not seem to call checkers for pre/post DeclRefExpr visits.
(Opened radar://10573500. To be fixed later on.)

llvm-svn: 146536
2011-12-14 00:56:18 +00:00
Anna Zaks 04b57c25bc [analyzer] Minor refactor to addTaint.
llvm-svn: 146535
2011-12-14 00:56:15 +00:00
Anna Zaks eefc0e9342 [analyzer] Mark output of fscanf and fopen as tainted.
llvm-svn: 146533
2011-12-14 00:56:02 +00:00
Anna Zaks d6bb3227de [analyzer] Mark getenv output as tainted.
Also, allow adding taint to a region (not only a symbolic value).

llvm-svn: 146532
2011-12-14 00:55:58 +00:00
Anna Zaks 7c96b7db96 [analyzer] CStringChecker should not rely on the analyzer generating UndefOrUnknown value when it cannot reason about the expression.
We are now often generating expressions even if the solver is not known to be able to simplify it. This is another cleanup of the existing code, where the rest of the analyzer and checkers should not base their logic on knowing ahead of the time what the solver can reason about. 

In this case, CStringChecker is performing a check for overflow of 'left+right' operation. The overflow can be checked with either 'maxVal-left' or 'maxVal-right'. Previously, the decision was based on whether the expresion evaluated to undef or not. With this patch, we check if one of the arguments is a constant, in which case we know that 'maxVal-const' is easily simplified. (Another option is to use canReasonAbout() method of the solver here, however, it's currently is protected.)

This patch also contains 2 small bug fixes:
 - swap the order of operators inside SValBuilder::makeGenericVal.
 - handle a case when AddeVal is unknown in GenericTaintChecker::getPointedToSymbol.

llvm-svn: 146343
2011-12-11 18:43:40 +00:00
Anna Zaks 170fdf1b5a [analyzer]Fixup r146336.
Forgot to commit the Header files. 
Rename generateUnknownVal -> makeGenericVal.

llvm-svn: 146337
2011-12-10 23:42:38 +00:00
Anna Zaks ecd730085d [analyzer] Introduce IntSymExpr, where the integer is on the lhs.
Fix a bug in SimpleSValBuilder, where we should swap lhs and rhs when calling generateUnknownVal(), - the function which creates symbolic expressions when data is tainted. The issue is not visible when we only create the expressions for taint since all expressions are commutative from taint perspective.

Refactor SymExpr::symbol_iterator::expand() to use a switch instead of a chain of ifs.

llvm-svn: 146336
2011-12-10 23:36:51 +00:00
Anna Zaks 6af472aa3b [analyzer] Fix inconsistency on when SValBuilder assumes that 2
types are equivalent.

+ A taint test which tests bitwise operations and which was
triggering an assertion due to presence of the integer to integer cast.

llvm-svn: 146240
2011-12-09 03:34:02 +00:00
Anna Zaks 394256cc0d [analyzer] If memory region is tainted mark data as tainted.
+ random comments

llvm-svn: 146199
2011-12-08 22:38:43 +00:00
Francois Pichet 311084734d Unbreak MSVC build.
llvm-svn: 146146
2011-12-08 09:32:22 +00:00
Peter Collingbourne 266e3dda17 Add an experimental MallocSizeofChecker, which reports inconsistencies
between the casted type of the return value of a malloc/calloc/realloc
call and the operand of any sizeof expressions contained within
its argument(s).

llvm-svn: 146144
2011-12-08 08:31:14 +00:00
Anna Zaks 9da86ce834 [analyzer] Cleanup: use the variable.
llvm-svn: 146056
2011-12-07 19:56:13 +00:00
Anna Zaks b86fdbe7e3 [analyzer] Propagate taint through MemRegions.
SVal can be not only a symbol, but a MemRegion. Add support for such
cases.

llvm-svn: 146006
2011-12-07 01:09:52 +00:00
Richard Smith 1e1f5abf77 DeadStoresChecker: when whitelisting dead initializations with constants, look
for a foldable constant rather than an IR-level constant. This is still far too
liberal, but is a step in the right direction.

llvm-svn: 145990
2011-12-06 23:25:15 +00:00
Anna Zaks 52fb9c08fc [analyzer] Add comments related to symbol_iterator
llvm-svn: 145987
2011-12-06 23:12:38 +00:00
Anna Zaks ee1a43533b [analyzer] Refactor: Move symbol_iterator from SVal to SymExpr, use it
for finding dependent symbols for taint.

llvm-svn: 145986
2011-12-06 23:12:33 +00:00
Anna Zaks c25efccc8b [analyzer] Propagate taint through NonLoc to NonLoc casts.
- Created a new SymExpr type - SymbolCast.
 - SymbolCast is created when we don't know how to simplify a NonLoc to
NonLoc casts.
 - A bit of code refactoring: introduced dispatchCast to have better
code reuse, remove a goto.
 - Updated the test case to showcase the new taint flow.

llvm-svn: 145985
2011-12-06 23:12:27 +00:00
Anna Zaks 8629c0a4d0 [analyzer] Remove an unnecessary check.
llvm-svn: 145984
2011-12-06 23:12:17 +00:00
Anna Zaks 02a1fc1da6 [analyzer] Rely on LLVM Dominators in Clang dominator computation.
(Previously, Clang used it's implementation of dominators.)

The patch is contributed by Guoping Long!

llvm-svn: 145858
2011-12-05 21:33:11 +00:00
Anna Zaks 5c10794254 [analyzer] Mark ConstraintManager::canReasonAbout as protected.
llvm-svn: 145857
2011-12-05 21:33:06 +00:00
Anna Zaks 2d2999821b [analyzer] Simplify the condition.
This is a fixup for r145832.

The extra clauses do not matter after we remove the dependency on canReasonAbout(InitVal) in r145832.

llvm-svn: 145856
2011-12-05 21:33:01 +00:00
Anna Zaks d066f79c80 [analyzer] Unify SymbolVal and SymExprVal under a single SymbolVal
class.

We are going into the direction of handling SymbolData and other SymExpr
uniformly, so it makes less sense to keep two different SVal classes.
For example, the checkers would have to take an extra step to reason
about each type separately.

The classes have the same members, we were just using the SVal kind
field for easy differentiation in 3 switch statements. The switch
statements look more ugly now, but we can make the code more readable in
other ways, for example, moving some code into separate functions.

llvm-svn: 145833
2011-12-05 18:58:30 +00:00
Anna Zaks a636fbe73f [analyzer] Remove all uses of ConstraintManager::canResonAbout() from
ExprEngine.

Teach SimpleConstraintManager::assumeSymRel() to propagate constraints
to symbolic expressions.

+ One extra warning (real bug) is now generated due to enhanced
assumeSymRel().

llvm-svn: 145832
2011-12-05 18:58:25 +00:00
Anna Zaks 51090d5f7f [analyzer] First step toward removing
ConstraintManager::canReasonAbout() from the ExprEngine.

ExprEngine should not care if the constraint solver can reason about
something or not. The solver should be able to handle all the SymExprs.

To do this, the solver should be able to keep track of not only the
SymbolData but of all SymExprs. This is why we change SymbolRef to be an
alias of SymExpr*. When encountering an expression it cannot simplify,
the solver should just add the constraints to it.

llvm-svn: 145831
2011-12-05 18:58:19 +00:00
Anna Zaks 820e87e928 [analyzer] Minor improvements on RangeConstraint pretty-printing.
llvm-svn: 145830
2011-12-05 18:58:14 +00:00
Anna Zaks 223516523e [analyzer] Change RetainCountChecker to use symbol dump method instead
of relying on SymbolID.

This way any expression can be printed (not only SymbolData).

llvm-svn: 145829
2011-12-05 18:58:11 +00:00
Anna Zaks f784d08d25 [analyzer] Add ability to do a simple ProgramState dump() without
requiring CFG.

Adding more ugly code; the evnvironment printing should be moved to
envirnment at some point.

llvm-svn: 145828
2011-12-05 18:58:08 +00:00
Anna Zaks 1c215d0a11 [analyzer] Add a debug checker to test for tainted data.
llvm-svn: 145827
2011-12-05 18:58:01 +00:00
Anna Zaks 719051e1c6 [analyzer] Make KeychainAPI checker less aggressive. radar://10508828
We trigger an error if free is called after a possibly failed allocation. Do not trigger the error if we know that the buffer is not null.

llvm-svn: 145584
2011-12-01 16:41:58 +00:00
Anna Zaks c6aa531a8f [analyzer] Refactor checkers to use helper function for getting callee Decl and name.
We are getting name of the called function or it's declaration in a few checkers. Refactor them to use the helper function in the CheckerContext. 

llvm-svn: 145576
2011-12-01 05:57:37 +00:00
Ted Kremenek 24fc93a940 When analyzing a C++ method (without a specific caller), assume 'this' is non-null. Fixes <rdar://problem/10508787>.
llvm-svn: 145575
2011-12-01 05:29:42 +00:00
Ted Kremenek 85825aebc9 Further tweak -Wurneachable-code and templates by allowing the warning to run on
explicit template specializations (which represent actual functions somebody wrote).

Along the way, refactor some other code which similarly cares about whether or
not they are looking at a template instantiation.

llvm-svn: 145547
2011-12-01 00:59:17 +00:00
Benjamin Kramer 9ce686e25f Update CMake build.
llvm-svn: 145506
2011-11-30 18:56:24 +00:00
Anna Zaks 92297f9dcc [analyzer] Add checker callback documentation.
llvm-svn: 145495
2011-11-30 17:12:52 +00:00
Ted Kremenek cfe4ff9725 Relax RegionStore to allow loads from CodeTextRegions. Apparently you can actually write code that does this. This seems worthy of a checker, but the StoreManager should handle the memory abstraction without crashing. Fixes PR 11450.
llvm-svn: 145424
2011-11-29 19:39:29 +00:00
Anna Zaks 951d205aec [analyzer] Minor cleanup of SValBuilder: Comments + code reuse.
llvm-svn: 145274
2011-11-28 20:43:37 +00:00
Anna Zaks 457c68726c [analyzer] Warn when non pointer arguments are passed to scanf (only when running taint checker).
There is an open radar to implement better scanf checking as a Sema warning. However, a bit of redundancy is fine in this case.

llvm-svn: 144964
2011-11-18 02:26:36 +00:00
Anna Zaks 040ddfedc0 [analyzer] Do not conjure a symbol when we need to propagate taint.
When the solver and SValBuilder cannot reason about symbolic expressions (ex: (x+1)*y ), the analyzer conjures a new symbol with no ties to the past. This helps it to recover some path-sensitivity. However, this breaks the taint propagation.

With this commit, we are going to construct the expression even if we cannot reason about it later on if an operand is tainted.

Also added some comments and asserts.

llvm-svn: 144932
2011-11-17 23:07:28 +00:00
Anna Zaks 89c00c9d3f [analyzer] Minor tweaks to the ProgramState::isTainted().
llvm-svn: 144928
2011-11-17 22:59:00 +00:00
Anna Zaks af36e9128a [analyzer] Add a helper method.
Naming could be improved.. But we should first rename the classes in the SVal hierarchy.

llvm-svn: 144927
2011-11-17 22:57:01 +00:00
Anna Zaks df6ca9fbee [analysis] Constify CheckerContext.
llvm-svn: 144871
2011-11-17 01:09:19 +00:00
Anna Zaks 871606d8de [analyzer] Put CheckerConext::getCalleeName out of line.
llvm-svn: 144870
2011-11-17 01:09:15 +00:00
Jim Goodnow II 8d21fc8239 Fixed crash with initializer lists and unnamed bitfields in the RegionStore
Manager. Added test to ensure proper binding of initialized values.
This patch fixes PR11249.

llvm-svn: 144831
2011-11-16 20:29:27 +00:00
Benjamin Kramer de2ac70c0a Update CMake build.
llvm-svn: 144829
2011-11-16 20:05:08 +00:00
Anna Zaks 20829c90be [analyzer] Catch the first taint propagation implied buffer overflow.
Change the ArrayBoundCheckerV2 to be more aggressive in reporting buffer overflows
when the offset is tainted. Previously, we did not report bugs when the state was
underconstrained (not enough information about the bound to determine if there is
an overflow) to avoid false positives. However, if we know that the buffer
offset is tainted - comes in from the user space and can be anything, we should
report it as a bug.

+ The very first example of us catching a taint related bug.
This is the only example we can currently handle. More to come...

llvm-svn: 144826
2011-11-16 19:58:17 +00:00
Anna Zaks 5c5bf9b634 [analyzer] Adding generic taint checker.
The checker is responsible for defining attack surface and adding taint to symbols.

llvm-svn: 144825
2011-11-16 19:58:13 +00:00
Anna Zaks ec7dc5c137 [analyzer] Adding basic building blocks for taint propagation.
TaintTag.h will contain definitions of different taint kinds and their properties.
TaintManager will be responsible for implementing taint specific operations, storing taint.
ProgramState will provide API to add/remove taint.

llvm-svn: 144824
2011-11-16 19:58:10 +00:00
Anna Zaks 6b1a955130 [analyzer] Cleanup: Null->0, comments.
llvm-svn: 144823
2011-11-16 19:58:05 +00:00
Anna Zaks 3888aa4beb [analyzer] Factor getCalleeName to the checker context.
many checkers are trying to get a name of the callee when visiting
a CallExpr, so provide a convenience API.

llvm-svn: 144820
2011-11-16 19:57:55 +00:00
Ted Kremenek 8e7fbcc3e4 [static analyzer] Tweak RetainCountChecker's diagnostics to correctly indicate if a message was due to a property access. This can
potentially be refactored for other clients, and this is a regression from the refactoring of property acceses.

llvm-svn: 144571
2011-11-14 21:59:21 +00:00