Commit Graph

5486 Commits

Author SHA1 Message Date
Jonas Jensen
189d82b79a C++: Change exclusion to not be only operator= 2019-01-18 11:19:38 +01:00
Robert Marsh
64ed9305d3 C++: new query for futile arguments to C functions 2019-01-17 10:45:10 -08:00
Jonas Jensen
f147b63bb8 Merge pull request #654 from geoffw0/lossyresultcast
CPP: Work on Lossy function result cast query
2019-01-17 17:07:29 +01:00
Jonas Jensen
9c42b5fab7 C++: Relax commented-out code heuristic for }
I looked through a few hundred results from this query on lgtm.com and
found that most of the FPs had to do with comment lines ending in `}`.
This change should fix most of them, at the cost of very few false
negatives.

On Wireshark, this query goes from 7,425 results to 6,686 results before
filtering for generated code. Almost all the lost results were FP,
except a handful of results involving initializer lists.
2019-01-17 10:20:48 +01:00
Jonas Jensen
92b48bf6af C++: Add another test for CommentedOutCode.ql 2019-01-17 09:15:25 +01:00
Jonas Jensen
dcb24e07c3 C++: Remove getFullyConverted call in sink def
With this change, the `IRDataflowTestCommon.qll` and
`DataflowTestCommon.qll` files use the same definitions of sources and
sinks. Since the IR data flow library is meant to be compatible with the
AST data flow library, this is what we ought to be testing.

Two alerts change but not necessarily for the right reasons.
2019-01-16 13:56:52 +01:00
Jonas Jensen
502b7cfe33 C++: Don't use C-style varargs in test.cpp sink
As we prepare to clarify how conversions are treated, we don't want a
`sink(...)` declaration where it's non-obvious which conversions are
applied to arguments.
2019-01-16 09:47:58 +01:00
Jonas Jensen
3edadc311f C++: Simplify skipInitializer in CFG.qll
The CFG construction code previously contained half of an approximation
of which address expressions are constant. Now this this property is
properly modelled by `Expr.isConstant`, we can remove this code.

This fixes most discrepancies between the QL-based CFG and the
extractor-based CFG on Wireshark.
2019-01-15 13:03:26 +01:00
Jonas Jensen
aaae5becf1 C++: Add addresses to Expr.isConstant
Before this change, `Expr.isConstant` only was only true for those
constant expressions that could be represented as QL values: numbers,
Booleans, and string literals. It was not true for string literals
converted from arrays to pointers, and it was not true for addresses of
variables with static lifetime.

The concept of a "constant expression" varies between C and C++ and
between versions of the standard, but they all include addresses of data
with static lifetime. These are modelled by the new library
`AddressConstantExpression.qll`, which is based on the code in
`EscapesTree.qll` and modified for its new purpose.

I've tested the change for performance on Wireshark and for correctness
with the included tests. I've also checked on Wireshark that all static
initializers in C files are considered constant, which was not the case
before.
2019-01-15 12:31:04 +01:00
Jonas Jensen
9751a91087 C++: Accept changes to alert message in test 2019-01-14 21:43:57 +01:00
Robert Marsh
eabc674bb3 Merge pull request #747 from jbj/cfg-remove-cfg.ql
C++: Delete library-tests/qlcfg/cfg.ql
2019-01-11 11:57:26 -08:00
Jonas Jensen
ef331ee68c Merge pull request #633 from Semmle/rdmarsh/cpp/range-analysis
C++: New range analysis
2019-01-11 19:32:20 +01:00
Jonas Jensen
6385dd38cf C++: Exclude operator= in ExprHasNoEffect 2019-01-11 13:30:08 +01:00
Jonas Jensen
95e457cb49 C++: Add test with FP in ExprHasNoEffect 2019-01-11 13:18:44 +01:00
Jonas Jensen
1cc36dd969 C++: Exclude copy assignment in LargeParameter.ql
The purpose of the copy assignment operator is to copy the object, so we
should not complain that a copy happens when passing the parameter. See
https://en.wikibooks.org/wiki/More_C++_Idioms/Copy-and-swap for details.
2019-01-11 12:00:02 +01:00
Jonas Jensen
4ea3849595 C++: Add failing test case for LargeParameter.ql 2019-01-11 11:53:04 +01:00
Jonas Jensen
88a251c05a C++: Delete library-tests/qlcfg/cfg.ql
This test was intended to catch regressions in the CFG, but it looks
like it's just catching insignificant extractor changes. The test has
started failing after some recent extractor changes, but I have no way
to pinpoint the failure and understand whether it's a problem or not, so
I think it's better to delete this test.

The remaining tests check whether the QL-based CFG generates the same
graph as the extractor-based CFG. Furthermore, the `successor-tests`
check that the extractor-based CFG works as intended.
2019-01-11 08:24:07 +01:00
Robert Marsh
c455db9e59 C++: update test expectations 2019-01-10 11:24:13 -08:00
Geoffrey White
28261d6787 Merge pull request #737 from jbj/cfg-perf
C++: QL CFG performance and tweaks
2019-01-10 14:45:53 +00:00
Geoffrey White
f2e68da322 CPP: Use dataflow to find wrapped rounding functions. 2019-01-10 14:44:11 +00:00
Geoffrey White
207c4d365a CPP: Test wrapped rounding functions more thoroughly. 2019-01-10 14:39:23 +00:00
Jonas Jensen
aa0f2f2da3 C++: Support ?: in UsingStrcpyAsBoolean.ql
I removed some unnecessary parentheses for symmetry, causing whitespace
changes.
2019-01-10 08:35:54 +01:00
Jonas Jensen
0f88a4b312 C++: Test ?: support in UsingStrcpyAsBoolean.ql
This test shows that the query only supports the ternary operator in
C++, not C.
2019-01-10 08:35:54 +01:00
Jonas Jensen
4dd36772ef C++: Remove UsingStrcpyAsBoolean.ql duplicates 2019-01-10 08:35:54 +01:00
Jonas Jensen
3a6a515a1d C++: Tabs to spaces and // Bug comments in test
This changes the column numbers in the expected test output.
2019-01-10 08:35:53 +01:00
Jonas Jensen
9219214d64 Merge pull request #695 from raulgarciamsft/users/raulga/c6324
cpp - Using the return value of a strcpy or related string copy function in an if statement
2019-01-10 08:34:17 +01:00
Geoffrey White
7a877bfe14 CPP: Add exception for wrapped whitelisted functions. 2019-01-09 18:30:19 +00:00
Geoffrey White
f983391cbf CPP: Add exception for pow. 2019-01-09 15:06:23 +00:00
Geoffrey White
11013b0ec6 CPP: Add a few more test cases. 2019-01-09 14:58:25 +00:00
Jonas Jensen
9146b8e32e C++: Add example of conditional destruction
The QL CFG and extractor CFG are the same, so the test passes. Neither
of them model that `ref` may or may not be destructed.
2019-01-09 15:02:25 +01:00
Geoffrey White
cbe69f2daf CPP: Fix false positive. 2019-01-09 13:59:24 +00:00
Geoffrey White
e26c709dbf CPP: Add a test for LossyFunctionResultCast.ql. 2019-01-09 13:59:24 +00:00
Geoffrey White
6088ca5d5b CPP: Update our uses of MacroInvocationExpr. 2019-01-09 12:17:29 +00:00
Geoffrey White
b59c2868cd CPP: Add test cases for the macro logic and other details of ArithmeticUncontrolled.ql. 2019-01-09 12:17:29 +00:00
Robert Marsh
0040a2d123 C++: respond to further PR comments 2019-01-08 09:34:28 -08:00
Robert Marsh
8c9c316e1b C++: performance and termination fixes 2019-01-08 09:34:27 -08:00
Robert Marsh
567eee1114 C++: allow phi nodes to self-bound 2019-01-08 09:34:27 -08:00
Robert Marsh
b2cd9a29f2 C++: add test for false comparisons 2019-01-08 09:34:26 -08:00
Robert Marsh
2f8ca8802b C++: switch to using ValueNumbers as bounds
This reduces the number of bounds computed, and will simplify use of the
library. The resulting locations in the tests may be slightly strange,
because the example `Instruction` for a `ValueNumber` is the first
appearing in the IR, regardless of source order, and may not be the most
closely related `Instruction` to the bounded value. I think that's worth
doing for the performance and usability benefits.
2019-01-08 09:34:26 -08:00
Robert Marsh
89148a9ec7 C++: respond to further PR comments 2019-01-08 09:34:26 -08:00
Robert Marsh
ae4ffd9166 C++: respond to PR comments, add some TODOs 2019-01-08 09:34:25 -08:00
Robert Marsh
fe32aea31f C++: fix/add comments 2019-01-08 09:34:25 -08:00
Robert Marsh
ed68f9150a C++: Initial implementation of new range analysis 2019-01-08 09:34:23 -08:00
Robert Marsh
a06a20dbab C++: move SimpleRangeAnalysis tests 2019-01-08 09:34:23 -08:00
Raul Garcia
18bb6696e0 Fixing conditional only issue.
I changed  to detect any logical operation usage (i.e. !, ==), but I kept usage in a conditional directly as a separate detection condition. I found no false positives on the projects you shared with me previously.
2019-01-07 10:44:11 -08:00
Raul Garcia
880306c621 Removing duplicated results 2019-01-04 10:45:43 -08:00
Jonas Jensen
26f32f0d6d C++: Initial version of CFG.qll
This implements calculation of the control-flow graph in QL. The new
code is not enabled yet as we'll need more extractor changes first.

The `SyntheticDestructorCalls.qll` file is a temporary solution that can
be removed when the extractor produces this information directly.
2019-01-04 13:34:36 +01:00
Jonas Jensen
8f9849b30b C++: Add BuiltInIntAddr class for __INTADDR__ 2019-01-04 10:24:08 +01:00
Ian Lynagh
98e8858dc6 C++: Accept test changes 2019-01-03 21:09:49 +00:00
Raul Garcia
28932e85d9 Fixing the code based on PR feedback. 2019-01-02 16:23:19 -08:00