Commit Graph

1255 Commits

Author SHA1 Message Date
Jean-Daniel Dupas 400dd1c3d0 Remove the "C" in "implicitly declaring C library function" diagnostic
because all functions are not C functions (i.e. NSLog).

llvm-svn: 149150
2012-01-27 23:21:02 +00:00
Anna Zaks 60835eb11e [analyzer] The CFContainer test should only be run on x86_64.
llvm-svn: 149042
2012-01-26 04:00:23 +00:00
Anna Zaks 06f10bf05a [analyzer] Add an AST checker that checks for a common pitfall when
using CFArrayCreate & family.

Specifically, CFArrayCreate's input should be:
'A C array of the pointer-sized values to be in the new array.'

(radar://10717339)

llvm-svn: 149008
2012-01-26 01:05:43 +00:00
Ted Kremenek 8e4c4266de Rework flushing of diagnostics to PathDiagnosticConsumer. Now all the reports are batched up before being flushed
to the underlying consumer implementation.  This allows us to unique reports across analyses to multiple functions (which
shows up with inlining).

llvm-svn: 148997
2012-01-25 23:47:14 +00:00
Eli Friedman 946b7b5bc8 Switch PerformImplicitConversion over to use DefaultLvalueConversion for lvalue-to-rvalue conversion.
llvm-svn: 148874
2012-01-24 22:51:26 +00:00
Anna Zaks bf740512ec [analyzer] Add more C taint sources/sinks.
llvm-svn: 148844
2012-01-24 19:32:25 +00:00
Anna Zaks 97bef5642e [analyzer] It's possible to have a non PointerType expression evaluate to a Loc value. When this happens, use the default type.
llvm-svn: 148631
2012-01-21 06:59:01 +00:00
Anna Zaks b7eac9fbef [analyzer] Make VLA checker taint aware.
Also, slightly modify the diagnostic message in ArrayBound and DivZero (still use 'taint', which might not mean much to the user, but plan on changing it later).

llvm-svn: 148626
2012-01-21 05:07:33 +00:00
Ted Kremenek e7b9d4342b Tighten format string diagnostic and make it a bit clearer (and a bit closer to GCC's).
llvm-svn: 148579
2012-01-20 21:52:58 +00:00
Anna Zaks 8298af85a6 [analyzer] Add taint awareness to DivZeroChecker.
llvm-svn: 148566
2012-01-20 20:28:31 +00:00
Ted Kremenek b9ff6b2302 Reenable DeadStoresChecker under --analyze, and move the IdempotentOperationsChecker to the 'experimental' category. Fixes <rdar://problem/10146347>.
llvm-svn: 148533
2012-01-20 06:00:17 +00:00
Ted Kremenek 89eaf8d531 Implement checker that looks for calls to mktemps and friends that have fewer than 6 Xs. Implements <rdar://problem/6336672>.
llvm-svn: 148531
2012-01-20 05:35:06 +00:00
Ted Kremenek c54dc9515d Turn 'SecuritySyntaxChecker' into a "meta" security checker for insecure APIs. Now
multiple checks are exposed as separate checkers, but CheckerManager only creates
one Checker object.

llvm-svn: 148525
2012-01-20 01:44:29 +00:00
Anna Zaks 3b754b25bd [analyzer] Add socket API as a source of taint.
llvm-svn: 148518
2012-01-20 00:11:19 +00:00
Fariborz Jahanian 28324b0066 objc: deprecate direct usage of 'isa' of objc objects
in favor of usage of api's intended for.
// rdar://8290002

llvm-svn: 148404
2012-01-18 19:08:56 +00:00
Anna Zaks 560dbe9ac9 [analyzer] Taint: warn when tainted data is used to specify a buffer
size (Ex: in malloc, memcpy, strncpy..)

(Maybe some of this could migrate to the CString checker. One issue
with that is that we might want to separate security issues from
regular API misuse.)

llvm-svn: 148371
2012-01-18 02:45:11 +00:00
Anna Zaks 5d324e509c [analyzer] Taint: add taint propagation rules for string and memory copy
functions.

llvm-svn: 148370
2012-01-18 02:45:07 +00:00
Anna Zaks 0244cd7450 [analyzer] Taint: add system and popen as undesirable sinks for taint
data.

llvm-svn: 148176
2012-01-14 02:48:40 +00:00
Anna Zaks cb6d4ee793 [analyzer] Unwrap the pointers when ignoring the const cast.
radar://10686991

llvm-svn: 148081
2012-01-13 00:56:55 +00:00
Anna Zaks 6228130099 [analyzer] RegionStoreManager::getBinding() should not crash when
looking up value at a CodeTextRegion even when the type is not provided.

llvm-svn: 148079
2012-01-13 00:56:48 +00:00
Ted Kremenek 52acee87f4 Adjust set of default checkers.
llvm-svn: 148055
2012-01-12 22:41:10 +00:00
Ted Kremenek 3d3aea9374 [analyzer] fix inlining's handling of mapping actual to formal arguments and limit the call stack depth. The analyzer can now accurately simulate factorial for limited depths.
llvm-svn: 148036
2012-01-12 19:25:46 +00:00
Anna Zaks b3fa8d7dd1 [analyzer] Add taint transfer by strcpy & others (part 1).
To simplify the process:
Refactor taint generation checker to simplify passing the
information on which arguments need to be tainted from pre to post
visit.

Todo: We need to factor out the code that sema is using to identify the
string and memcpy functions and use it here and in the CString checker.

llvm-svn: 148010
2012-01-12 02:22:34 +00:00
Ted Kremenek 940e00f299 "This change adds alloca/valloc checks to UnixAPIChecker. It includes a small refactoring for
the common *alloc functions as well as a few tiny wibbles (adds a note
to CWE/CERT advisory numbers in the bug output, and fixes a couple
80-column-wide violations.)"

Patch by Austin Seipp!

llvm-svn: 147931
2012-01-11 08:13:21 +00:00
Zhongxing Xu f0cb43f561 Add elidable CXXConstructExpr as block-level expr. It converts an lvalue to a rvalue, which is a useful step during AST evaluation.
llvm-svn: 147918
2012-01-11 02:39:07 +00:00
Ted Kremenek 3f406ba4bf Remove '#if 0' from ExprEngine::InlineCall(), and start fresh by wiring up inlining for straight C calls.
My hope is to reimplement this from first principles based on the simplifications of removing unneeded node builders
and re-evaluating how C++ calls are handled in the CFG.  The hope is to turn inlining "on-by-default" as soon as possible
with a core set of things working well, and then expand over time.

llvm-svn: 147904
2012-01-11 01:06:27 +00:00
Anna Zaks 126a2ef920 [analyzer] Add basic format string vulnerability checking.
We already have a more conservative check in the compiler (if the
format string is not a literal, we warn). Still adding it here for
completeness and since this check is stronger - only triggered if the
format string is tainted.

llvm-svn: 147714
2012-01-07 02:33:10 +00:00
Anna Zaks e04dadc248 [analyzer] Add another tests to taint tester.
llvm-svn: 147570
2012-01-04 23:54:04 +00:00
Anna Zaks 8158ef0dec [analyzer] Be less pessimistic about invalidation of global variables
as a result of a call.

Problem:
Global variables, which come in from system libraries should not be
invalidated by all calls. Also, non-system globals should not be
invalidated by system calls.

Solution:
The following solution to invalidation of globals seems flexible enough
for taint (does not invalidate stdin) and should not lead to too
many false positives. We split globals into 3 classes:

* immutable - values are preserved by calls (unless the specific
global is passed in as a parameter):
     A :  Most system globals and const scalars

* invalidated by functions defined in system headers:
     B: errno

* invalidated by all other functions (note, these functions may in
turn contain system calls):
     B: errno
     C: all other globals (which are not in A nor B)

llvm-svn: 147569
2012-01-04 23:54:01 +00:00
Ted Kremenek 5799cddde0 Extend ConditionBRVisitor to handle condition variable assignments.
llvm-svn: 147526
2012-01-04 08:18:09 +00:00
Ted Kremenek 990464cb30 Teach the static analyzer to not treat XPC types as CF types.
llvm-svn: 147506
2012-01-04 00:35:48 +00:00
Ted Kremenek 134a83a799 Enhance UnixAPIChecker to also warn about zero-sized allocations to calloc() and realloc(). Patch by Cyril Roelandt!
llvm-svn: 147500
2012-01-03 23:43:13 +00:00
Ted Kremenek b3512d3a48 Add initial version of checker to check if virtual member functions are called transitively
from C++ constructors or destructors.  Checker by Lei Zhang with a few tweaks by Ted Kremenek.

llvm-svn: 147494
2012-01-03 23:18:57 +00:00
Ted Kremenek 72be32af88 Colorize and condense CFG pretty-printing.
llvm-svn: 147203
2011-12-22 23:33:52 +00:00
Ted Kremenek 5586354d7d Fix typos in analyzer diagnostics pointed out by Matt Beaumont-Gay and Robert Purves.
llvm-svn: 147139
2011-12-22 06:35:52 +00:00
Ted Kremenek c177d9faf5 Fix regression in LiveVariables when reasoning about variables captured by blocks.
llvm-svn: 147116
2011-12-22 00:46:32 +00:00
Anna Zaks 5f847144d1 [analyzer] Do not invalidate arguments when the parameter's
type is a pointer to const. (radar://10595327)

The regions corresponding to the pointer and reference arguments to
a function get invalidated by the calls since a function call can
possibly modify the pointed to data. With this change, we are not going
to invalidate the data if the argument is a pointer to const. This
change makes the analyzer more optimistic in reporting errors.
(Support for C, C++ and Obj C)

llvm-svn: 147002
2011-12-20 22:35:30 +00:00
Ted Kremenek a1745c24c4 Fix inversion of static analyzer path diagnostics for path conditions.
llvm-svn: 146993
2011-12-20 22:00:25 +00:00
Dylan Noblesmith fb75874697 test/Analysis: fix error message
llvm-svn: 146848
2011-12-18 18:07:42 +00:00
Anna Zaks 79b5c26014 [analyzer] Fixup for r146793. Add tests for atol and atoll.
llvm-svn: 146794
2011-12-17 00:30:16 +00:00
Anna Zaks 3b0ab206d2 [analyzer] Add support for taint flowing through a function (atoi).
Check if the input parameters are tainted (or point to tainted data) on
a checkPreStmt<CallExpr>. If the output should be tainted, record it in
the state. On post visit (checkPostStmt<CallExpr>), use the state to
make decisions (in addition to the existing logic). Use this logic for
atoi and fscanf.

llvm-svn: 146793
2011-12-17 00:26:34 +00:00
Anna Zaks e48ee50324 [analyzer] Better stdin support.
llvm-svn: 146748
2011-12-16 18:28:50 +00:00
Anna Zaks a2510070ee Add support for matching one or more (aka regex +) diagnostic messages with -verify.
Ex:
// expected-warning + {{tainted}

llvm-svn: 146633
2011-12-15 02:28:16 +00:00
Anna Zaks 30373150a1 [analyzer] Ensure that the order in which checker callbacks are called
is deterministic.

Non-determinism was the reason for the test which caused the earlier
buildbot failures, so re-enable the test.

llvm-svn: 146628
2011-12-15 01:36:04 +00:00
Richard Trieu 553b2b2e5d Modify how the -verify flag works. Currently, the verification string and
diagnostic message are compared.  If either is a substring of the other, then
no error is given.  This gives rise to an unexpected case:

  // expect-error{{candidate function has different number of parameters}}

will match the following error messages from Clang:

  candidate function has different number of parameters (expected 1 but has 2)
  candidate function has different number of parameters

It will also match these other error messages:

  candidate function
  function has different number of parameters
  number of parameters

This patch will change so that the verification string must be a substring of
the diagnostic message before accepting.  Also, all the failing tests from this
change have been corrected.  Some stats from this cleanup:

87 - removed extra spaces around verification strings
70 - wording updates to diagnostics
40 - extra leading or trailing characters (typos, unmatched parens or quotes)
35 - diagnostic level was included (error:, warning:, or note:)
18 - flag name put in the warning (-Wprotocol)

llvm-svn: 146619
2011-12-15 00:38:15 +00:00
Anna Zaks 93237e4808 [analyzer] Disable verification step on the failing test.
I need to keep the test itself in the repository since it's the only way I can currently reproduce the issue.

llvm-svn: 146582
2011-12-14 19:39:46 +00:00
Anna Zaks 72e90d54ae [analyzer] Re-enable the test which was failing on one of the bots.
I cannot reproduce the failures neither on my machine nor on the same buildbot machine (with the clang binary built on it). Let's see if it fails again..

llvm-svn: 146574
2011-12-14 18:34:17 +00:00
Anna Zaks 87ebe63542 [analyzer] Revert the taint test, which is failing on one of the bots for time being.
llvm-svn: 146541
2011-12-14 02:00:54 +00:00
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 eefc0e9342 [analyzer] Mark output of fscanf and fopen as tainted.
llvm-svn: 146533
2011-12-14 00:56:02 +00:00