Commit Graph

1778 Commits

Author SHA1 Message Date
Tom Hvitved
86721ff800 C#: Add more documentation to SuccSplits module 2019-01-28 14:12:17 +01:00
Tom Hvitved
50522caa6e C#: Improve performance of CFG split set computation
Rewrite the predicate `succSplits()` and the construction of the IPA type `TSplits`.
The two are now mutually dependent, see more in the comment for the module
`SuccSplits`.
2019-01-25 14:35:56 +01:00
Tom Hvitved
dd99525566 C#: Redefine AccessorCall
The syntactic node assiociated with accessor calls was previously always the
underlying member access. For example, in

```
x.Prop = y.Prop;
```

the implicit call to `x.set_Prop()` was at the syntactic node `x.Prop`, while the
implicit call to `y.get_Prop()` was at the syntactic node `y.Prop`.

However, this breaks the invariant that arguments to calls dominate the call itself,
as the argument `y.Prop` for the implicit `value` parameter in `x.set_Prop()` will
be evaluated after the call (the left-hand side in an assignment is evaluated before
the right-hand side).

The solution is to redefine the access call to `x.set_Prop()` to point to the whole
assignment `x.Prop = y.Prop`, instead of the access `x.Prop`. For reads, we still want
to associate the accessor call with the member access.

A corner case arises when multiple setters are called in a tuple assignment:

```
(x.Prop1, x.Prop2) = (0, 1)
```

In this case, we cannot associate the assignment with both `x.set_Prop1()` and
`x.set_Prop2()`, so we instead revert to using the underlying member accesses as
before.
2019-01-18 13:56:23 +01:00
Tom Hvitved
2caf724826 C#: Add more tests 2019-01-18 12:07:22 +01:00
Tom Hvitved
9031e19c88 C#: Recognize ref assignments through delegate calls 2019-01-16 15:53:31 +01:00
Tom Hvitved
fc5076b466 C#: Add test for assignment through delegate ref argument 2019-01-16 15:22:45 +01:00
Tom Hvitved
b2f99dbbc7 C#: Teach data flow library about CFG splitting
Data flow nodes for expressions do not take CFG splitting into account. Example:

```
if (b)
    x = tainted;
x = x.ToLower();
if (!b)
    Use(x);
```

Flow is incorrectly reported from `tainted` to `x` in `Use(x)`, because the step
from `tainted` to `x.ToLower()` throws away the information that `b = true`.

The solution is to remember the splitting in data flow expression nodes, that is,
to represent the exact control flow node instead of just the expression. With that
we get flow from `tainted` to `[b = true] x.ToLower()`, but not from `tainted` to
`[b = false] x.ToLower()`.

The data flow API remains unchanged, but in order for analyses to fully benefit from
CFG splitting, sanitizers in particular should be CFG-based instead of expression-based:

```
if (b)
   x = tainted;
   if (IsInvalid(x))
       return;
Use(x);
```

If the call to `IsInvalid()` is a sanitizer, then defining an expression node to be
a sanitizer using `GuardedExpr` will be too conservative (`x` in `Use(x)` is in fact
not guarded). However, `[b = true] x` in `[b = true] Use(x)` is guarded, and to help
defining guard-based sanitizers, the class `GuardedDataFlowNode` has been introduced.
2019-01-16 10:39:27 +01:00
Tom Hvitved
f768abb0e6 C#: Add data flow test with CFG splitting 2019-01-16 10:29:26 +01:00
Tom Hvitved
abb3f71ec8 C#: Add GuardedControlFlowNode 2019-01-16 10:29:26 +01:00
Tom Hvitved
f323049b9d C#: CFG for expressions without enclosing callables, e.g. field initializers 2019-01-16 10:29:26 +01:00
Tom Hvitved
901f389a7d C#: Add CFG tests for field/property initializers 2019-01-16 10:29:26 +01:00
Calum Grant
6cc4c2d31f Merge pull request #762 from hvitved/csharp/autoformat/libraries
C#: Autoformat QLL files
2019-01-15 12:19:50 +00:00
Calum Grant
d4d5c47adb Merge pull request #749 from hvitved/csharp/remove-def-use
C#: Remove `DefUse.qll`
2019-01-15 10:52:39 +00:00
Tom Hvitved
f90b0fd16f C#: Convert some multi-line comments 2019-01-14 14:08:54 +01:00
Tom Hvitved
390ebc96ae C#: Autoformat QL files 2019-01-11 13:55:28 +01:00
Tom Hvitved
c06fc2af09 C#: Remove DefUse.qll 2019-01-11 09:35:38 +01:00
Calum Grant
89becbce9a Merge pull request #726 from hvitved/csharp/cfg/foreach-multi-variables
C#: Fix CFG for `foreach` statements with tuple declarations
2019-01-09 14:47:01 +00:00
Tom Hvitved
6fccfa3b0a C#: Fix CFG for foreach statements with tuple declarations 2019-01-04 18:51:55 +01:00
Tom Hvitved
72b3514970 C#: Add CFG tests for foreach statements with multipe variable declarations 2019-01-04 18:17:48 +01:00
Max Schaefer
b4f400fb23 Merge remote-tracking branch 'upstream/next' into qlucie/master 2019-01-04 10:35:57 +00:00
Tom Hvitved
5879e58741 C#: Account for CFG splitting in AssignableDefinition::getAFirstRead() and AssignableRead::getANextRead() 2019-01-02 09:50:13 +01:00
Tom Hvitved
f06a20f666 C#: Add SSA tests with CFG splitting 2019-01-02 09:48:04 +01:00
calumgrant
1b11abfec7 Merge pull request #709 from hvitved/csharp/autoformat/tests
C#: Autoformat QL tests
2018-12-21 11:12:31 +00:00
Tom Hvitved
5478155155 Merge pull request #615 from calumgrant/cs/extractor-caching
C# extractor: Improve performance by changing the caching
2018-12-21 09:36:43 +01:00
calum
d73b28efe4 C#: Address review comments.
Add more tests for duplicated entities, and fix some duplicated entities.
    Update the TupleTypes output - some extraneous results gone so it's probably better.
2018-12-20 20:23:12 +00:00
Tom Hvitved
af38a2b9c5 Merge branch 'master' into csharp/autoformat/tests 2018-12-20 20:59:10 +01:00
calumgrant
7dd263b413 Merge pull request #689 from hvitved/csharp/remove-get-url
C#: Remove `getUrl()` predicates
2018-12-20 18:49:15 +00:00
calum
d687dd9deb C#: Address review comments. Replace GetHashValue() with MetadataTokens.GetToken().
C#: Make path IDs consistent.
2018-12-20 13:02:25 +00:00
Tom Hvitved
231465143d C#: Autoformat QL tests 2018-12-20 10:19:59 +01:00
Tom Hvitved
546d750045 C#: Reintroduce getURL()
It turns out that we still need `getURL()` to account for cases where there is no
`getLocation()`. Not having `getURL()` for entities without a `getLocation()` results
in a `file://0:0:0:0` URL, which is not rendered in QL4E, unlike a `""` URL.
2018-12-19 20:47:33 +01:00
Tom Hvitved
b2500a0c26 Merge branch 'master' into csharp/maybe-null-path-query 2018-12-19 20:22:19 +01:00
calum
2acde22f43 C#: Add QL and tests for handles. 2018-12-19 15:22:53 +00:00
calumgrant
e15481a622 Merge pull request #702 from hvitved/csharp/remove-deprecated
C#: Remove deprecated predicates
2018-12-19 12:10:49 +00:00
calum
6a54a6d3e5 C#: Fix changed unit tests. 2018-12-19 11:03:05 +00:00
Tom Hvitved
edf1df1577 C#: Remove tests for deprecated predicates 2018-12-18 10:43:12 +01:00
Tom Hvitved
e14259126e Merge pull request #658 from calumgrant/cs/extractor/for-is
C#: Fix extraction bug for variable declarations in for condition
2018-12-17 16:16:00 +01:00
calumgrant
dbd0c7e80a Merge pull request #674 from hvitved/csharp/cache-get-label
C#: Cache `NamedElement::getLabel()`
2018-12-17 14:24:01 +00:00
Tom Hvitved
5f269b2d87 Merge branch 'master' into cs/extractor/for-is 2018-12-17 11:14:50 +01:00
Tom Hvitved
ada0115d6a C#: Remove getUrl() predicates
As described on https://lgtm.com/help/ql/locations#providing-location-information,
there is no need to provide a `getUrl()` predicate, when there is a `getLocation()`
predicate. Not only is it redundant, but it can also be slow because of string
construction.
2018-12-17 10:52:24 +01:00
Tom Hvitved
e2f271bddb C#: Add more guard implication steps 2018-12-14 12:03:32 +00:00
Tom Hvitved
b11d5c5075 Merge pull request #679 from calumgrant/cs/omitted-array-size
C#: Extract stackalloc initializers
2018-12-14 07:48:46 +01:00
calumgrant
8e546a30b0 Merge pull request #637 from hvitved/csharp/cfg/throwing-callable
C#: Fix a bug in `ThrowingCallable`
2018-12-12 16:58:28 +00:00
calum
2bbd55519b C#: Add tests for C# 7.3 features. 2018-12-12 16:44:55 +00:00
Tom Hvitved
1366638f06 C#: Fix whitespaces 2018-12-12 13:13:13 +01:00
calum
8d072863df C#: Reorder for statements to ensure variables declared in the condition are declared before they are used. 2018-12-11 10:31:45 +00:00
calumgrant
67d4099e3f Merge pull request #593 from hvitved/csharp/nullness
C#: Rewrite nullness queries
2018-12-07 15:57:27 +00:00
Tom Hvitved
c887dc89dc C#: Fix a bug in ThrowingCallable
A method such as

```
void M()
{
    throw new Exception();
}
```

was incorrectly not categorized as a `ThrowingCallable`, that is, a callable
that always throws an exception upon invocation.
2018-12-07 10:56:11 +01:00
Tom Hvitved
243af36167 C#: Add more CFG tests with throwing methods 2018-12-07 10:43:45 +01:00
calum
919d7cbf01 C#: Fix [INVALID_KEY] errors. 2018-12-05 13:55:55 +00:00
Tom Hvitved
4739a6334e C#: Fix a bug and generalize guards implication logic 2018-12-03 15:33:00 +01:00