Commit Graph

2725 Commits

Author SHA1 Message Date
AndreiDiaconu1
7390606370 Tidy up + more comment
Tidied up the code for review
Added more comments
2019-08-28 12:25:14 +01:00
AndreiDiaconu1
0c6ffc9f4d Casts and IsExpr
Fixed some inconsistencies with casts
Fixed some bugs related to which translated elements need loads
Added support for IsExpr expressions
2019-08-28 12:25:14 +01:00
AndreiDiaconu1
c8a3f6fac8 Added cast exprs + deleted commented code 2019-08-28 12:25:14 +01:00
AndreiDiaconu1
23694bdd14 Work on classes + refactor
Began working o inheritance, polymorphism and constructor init. Correct code is produced for them (though some more work is needed to accurately treat conversions between classes).
Removed commented code.
Added classes to properly deal with constructor init and modified and refactored TranslatedFunction to accomodate for the changes.
2019-08-28 12:25:14 +01:00
AndreiDiaconu1
9018b25177 Properties
Properties and property access produce correct code.
Fixed a function qualifier bug in `TranslatedCall.qll`.
Added a new class to translate `ExprStmt`s whose expr is an `AssignExpr` whose lvalue is an accessor call: we translate only the accessor call in for the translated AST.
2019-08-28 12:25:14 +01:00
AndreiDiaconu1
1acabc7d87 Jump statements
Broke down the class `TranslatedJump` to have more control on the IR control flow.
Now GotoLabelStmt, GotoCaseStmt, GotoDefaultStmt and BreakStmt are translated separately.
This also fixes an issue when having a switch as the last statement of a void function would create an incorrect CFG.
2019-08-28 12:25:13 +01:00
AndreiDiaconu1
2724075dec Added stmts
Added support for `ForStmt` and `DoWhileStmt`
Added test cases
2019-08-28 12:25:13 +01:00
AndreiDiaconu1
b6287b904c Preliminary refactoring
Some preliminary refactoring of the TranslatedDeclaration.qll file
2019-08-28 12:25:13 +01:00
AndreiDiaconu1
1e4b3fafb6 Updated expected for crement ops 2019-08-28 12:25:13 +01:00
AndreiDiaconu1
940ba694d2 Arithmetic increment and decrement expressions
Correct code is now produced for increment and decrement expressions
Modified producesExprResult() and TTranslatedLoad() so that no loads are done from outside the crement exprs and that the VariableAddress generated from the access of the operator variable is recognized as an expr that produces result.
2019-08-28 12:25:13 +01:00
AndreiDiaconu1
3bc6456572 Work on throw statements, bug fixes, small refactor.
Throw statements now give correct code, apart from the case of rethrows: need to make explicit the fact that a finally block is executed even if stack unwinding happens.
Added 2 new classes to TranslatedStmt.qll, one for throws that have an exception, one for rethrows.
Fixed a bug in TranslatedDeclarationEntry.qll where some local declaration would be missed.
Changed toString into getQualifiedName for more clarity when generating the instructions in Instruction.qll.
Some general refactoring in TranslatedExpr.qll and TranslatedStmt.qll.
2019-08-28 12:25:13 +01:00
AndreiDiaconu1
b90bc96cb5 Objects tests and fix in PrintIR
Added tests to showcase the instructions generated for object creation and object initialization
Updated raw_ir.expected
PrintIR now uses the qualified name (with types) when printing the IR for more clarity
2019-08-28 12:25:13 +01:00
Andrei Diaconu
dae37e5472 Fixed bugs, updated tests
Fixed a bug in TranslatedExpr: decl + init where the rhs is a reference now work as expected
Uncommented the code for the switch statement
2019-08-28 12:25:13 +01:00
Andrei Diaconu
be01b031b0 Fixed and refactored code for arrays
Introduced 2 new tags to support multidimensional arrays
Multidimensional arrays produce correct code
All types of initializations for arrays work correctly
2019-08-28 12:25:13 +01:00
AndreiDiaconu1
49777636aa Applied the review comments 2019-08-28 12:25:13 +01:00
Dave Bartolomeo
609ca034c0 C#/C++: Share IR implementation 2019-08-28 12:25:13 +01:00
Andrei Diaconu
45455a12d6 Fixed function calls
Function calls now produce correct code.
Added 2 test cases to showcase this.
2019-08-28 12:25:13 +01:00
Andrei Diaconu
26bf7e116d Arrays fixed, simple variable initialization fixed.
Correct code is now generated for array initialization and element access.
Created a new binary Opcode, `IndexedElementAddress`, used to get the address of an array element, similar to how CIL does it.
Fixed simple variable initialization.
2019-08-28 12:25:13 +01:00
Andrei Diaconu
aea0356994 Fixed var addressing and other changes
Now variables addressing correctly gets translated
Added a new test case to showcase this
Changed VoidType to ObjectType for the type of the 2 instructions
generated by as the prelude of a translated function
(UnmodeledDefinition and AliasedDefinition)
2019-08-28 12:25:13 +01:00
Andrei Diaconu
025d68f07a General tidy up and refactor
Refactored the C++ specific names
Tidied the code
Updated TODOs
2019-08-28 12:25:13 +01:00
Andrei Diaconu
c733bc0ae9 Functional basic porting
Ported basic functionalities from the C++ IR
Added a simple test that passes the IR sanity check and produces
sensible IR (together with the .expected files) to the C# test folder
2019-08-28 12:25:13 +01:00
Tom Hvitved
16f40fd45a C#: Consolidate CFG tests 2019-08-23 15:25:01 +02:00
Tom Hvitved
c5d9d74c0a C#: Nested field flow 2019-08-23 09:25:05 +02:00
Calum Grant
ff20a2ceb9 Merge pull request #1761 from hvitved/csharp/dataflow/fields
C#: Data flow through fields
2019-08-22 20:46:00 +01:00
Tom Hvitved
d2f8b0bc20 C#: Handle constructors with member initializers and base() calls in CFG 2019-08-22 10:34:23 +02:00
Tom Hvitved
5d140930d0 C#: Add field initializers to CFG for constructors
This commit adds field initializers to the CFG for non-static constructors. For
example, in

```
class C
{
    int Field1 = 0;
    int Field2 = Field1 + 1;
    int Field3;

    public C()
    {
        Field3 = 2;
    }

    public C(int i)
    {
        Field3 = 3;
    }
}
```

the initializer expressions `Field1 = 0` and `Field2 = Field1 + 1` are added
to the two constructors, mimicking

```
public C()
{
    Field1 = 0;
    Field2 = Field1 + 1;
    Field3 = 2;
}
```

and

```
public C()
{
    Field1 = 0;
    Field2 = Field1 + 1;
    Field3 = 3;
}
```

respectively. This means that we no longer have to synthesize calls, callables,
parameters, and arguments in the data flow library, so much of the work from
d1755500e4 can be simplified.
2019-08-21 16:21:38 +02:00
Tom Hvitved
eb97d7beaa Revert "C#: Generalize CFG entry/exit nodes to include field/property initializers"
This reverts commit b7e732fddb.
2019-08-21 09:55:24 +02:00
Jonas Jensen
11583b69e0 C#: Use pyrameterized modules for TaintTracking
To keep the code changes minimal, and to keep the implementation similar
to C++ and Java, the `TaintTracking{Public,Private}` files are now
imported together through `TaintTrackingUtil`. This has the side effect
of exposing `localAdditionalTaintStep`. The corresponding predicate for
Java was already exposed.
2019-08-20 13:45:38 +02:00
Tom Hvitved
d1755500e4 C#: Data flow through fields
Initial implementation of data flow through fields, using the algorithm of the
shared data flow implementation. Fields (and field-like properties) are covered,
and stores can be either
 - ordinary assignments, `Foo = x`,
 - object initializers, `new C() { Foo = x }`, or
 - field initializers, `int Foo = x`.

For field initializers, we need to synthesize calls (`SynthesizedCall`),
callables (`SynthesizedCallable`), parameters (`InstanceParameterNode`), and
arguments (`SynthesizedThisArgumentNode`), as the C# extractor does not (yet)
extract such entities. For example, in

```
class C
{
    int Field1 = 1;
    int Field2 = 2;

    C() { }
}
```

there is a synthesized call from the constructor `C`, with a synthesized `this`
argument, and the targets of that call are two synthesized callables with bodies
`this.Field1 = 1` and `this.Field2 = 2`, respectively.

A consequence of this is that `DataFlowCallable` is no longer an alias for
`DotNet::Callable`, but instead an IPA type.
2019-08-16 15:49:37 +02:00
Calum Grant
0df9a625ba Merge pull request #1717 from hvitved/csharp/ssa/adjacent-perf
C#: Improve performance of SSA adjacent reads calculation
2019-08-16 12:11:57 +01:00
Tom Hvitved
b7e732fddb C#: Generalize CFG entry/exit nodes to include field/property initializers 2019-08-16 13:06:51 +02:00
Calum Grant
b28241ac6d Merge pull request #1741 from hvitved/csharp/extract-field-inits
C#: Extract assignments for field/property initializers
2019-08-16 11:51:37 +01:00
Tom Hvitved
495e5bc628 C#: Extract assignments for field/property initializers 2019-08-15 16:18:23 +02:00
Calum Grant
3fab5140a7 Merge pull request #1673 from hvitved/csharp/cfg/split-static-limit
C#: Apply static CFG splitting limit
2019-08-15 10:04:38 +01:00
semmle-qlci
e27b373062 Merge pull request #1548 from hvitved/csharp/cfg/simplify-goto-completions
Approved by calumgrant
2019-08-12 19:20:48 +01:00
Tom Hvitved
5ecf680cc2 C#: Improve performance of SSA adjacent reads calculation
- Speedup the `varBlockReaches()` predicate, by restricting to basic blocks
  in which a given SSA definition may still be live, in constrast to just
  being able to reach *any* access (read or write) to the underlying source
  variable.
- Account for some missing cases in the `lastRead()` predicate.
2019-08-08 16:21:57 +02:00
Tom Hvitved
6749bbd438 C#: Make use of extra data flow copies 2019-08-07 10:41:43 +02:00
Tom Hvitved
4774bc969a C#: Apply static CFG splitting limit
The predicate `maxSplits()` was previously applied dynamically to ensure that
any control flow node would keep track of at most `maxSplits()` number of splits.
However, there was no guarantee that two different copies of the same AST element
wouldn't contain different splits, so in general the number of copies for a given
AST element `e` could be on the order `$\binom{n}{k}c^k$`, where `n` is the total
number of splits that apply to `e`, `k = maxSplits()`, and `c` is a constant.

With this change, the relevant splits for `e` are instead computed statically,
meaning that the order is instead `$c^k$`.
2019-08-06 11:38:03 +02:00
Calum Grant
2df05090b5 Merge pull request #1685 from hvitved/csharp/dataflow/out-flow-fix
C#: Fix data flow for `out`/`ref` parameters
2019-08-06 09:31:17 +01:00
Luke Cartey
54d01bdeff Merge pull request #1648 from hvitved/csharp/unchecked-return-lambda
C#: Fix false positives in `cs/unchecked-return-value`
2019-08-02 21:48:38 -07:00
Tom Hvitved
4d58154ff5 C#: Fix data flow for out/ref parameters 2019-08-02 14:25:38 -07:00
Tom Hvitved
04db1bf3f4 C#: Add data flow test for methods with multiple out/ref parameters 2019-08-02 13:46:18 -07:00
Tom Hvitved
b7d6165d42 C#: Convert cs/web/xss to a path-problem 2019-08-01 15:58:57 -07:00
Tom Hvitved
5c127ef20d C#: Fix false positives in cs/unchecked-return-value 2019-07-29 17:32:21 -07:00
Tom Hvitved
b6f3f7866b C#: Add more tests for cs/unchecked-return-value 2019-07-29 15:40:22 -07:00
Tom Hvitved
8a35813e1c C#: Unify goto completions 2019-07-05 07:21:34 +02:00
semmle-qlci
0290c79c54 Merge pull request #1486 from hvitved/csharp/inherited-completions
Approved by calumgrant
2019-07-04 19:45:25 +01:00
Tom Hvitved
421e75d4c1 C#: Address review comments 2019-07-04 11:57:48 +02:00
semmle-qlci
4f3cbe0029 Merge pull request #1521 from hvitved/csharp/constant-condition-fp
Approved by calumgrant
2019-07-01 10:52:14 +01:00
Arthur Baars
af68fd4904 Merge pull request #1408 from calumgrant/cs/suppress-null-expr
C#: C#8 Nullable expressions and type annotations
2019-06-28 19:21:46 +02:00