Commit Graph

8663 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
34bafa7230 Fixed sanity checks
Fixed a bug in `TranslatedArrayExpr` that would prevent the element to produce the correct instruction result, hence creating problems with loads and stores.
`ElementsAddress` opcode now inherits from the `UnaryOpcode`, as it should.
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
8661074fc3 Object creation and initialization + refactoring
Correct code is now generated from ObjectCreation exprs and ObjectInitializer exprs.
Removed TranslatedFieldInitialization and its subclasses and further refactored TranslatedInitialization
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
Andrei Diaconu
35b028e626 Initial work for objects and statements
Objects now work, although I will refactor the code quite a bit for clarity
If and while statements now produce good code
Began work on try statements
2019-08-28 12:25:13 +01:00
Andrei Diaconu
4462babc0b Added support for switch stmt (CS 6.0 style) 2019-08-28 12:25:13 +01:00
AndreiDiaconu1
49777636aa Applied the review comments 2019-08-28 12:25:13 +01:00
AndreiDiaconu1
ffb22bfff8 Locatable -> Language::AST 2019-08-28 12:25:13 +01:00
Andrei Diaconu
9105641741 Update csharp/ql/src/semmle/code/csharp/ir/IRSanity.ql
Co-Authored-By: Dave Bartolomeo <42150477+dave-bartolomeo@users.noreply.github.com>
2019-08-28 12:25:13 +01:00
Andrei Diaconu
81d8905a0f Update csharp/ql/src/semmle/code/csharp/ir/PrintIR.ql
Co-Authored-By: Dave Bartolomeo <42150477+dave-bartolomeo@users.noreply.github.com>
2019-08-28 12:25:13 +01:00
Andrei Diaconu
ce06bd8af3 Update csharp/ql/src/semmle/code/csharp/ir/implementation/raw/IRSanity.ql
Co-Authored-By: Dave Bartolomeo <42150477+dave-bartolomeo@users.noreply.github.com>
2019-08-28 12:25:13 +01:00
Andrei Diaconu
d8f8b47605 Update csharp/ql/src/semmle/code/csharp/ir/implementation/raw/PrintIR.ql
Co-Authored-By: Dave Bartolomeo <42150477+dave-bartolomeo@users.noreply.github.com>
2019-08-28 12:25:13 +01:00
Dave Bartolomeo
073812b6f1 Rename Cpp -> CSharp 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
50ba4d1fda Deleted folder 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
2a41e7b5c0 Fixed issues mentioned in the PR comments
Modified _.getCallable() to _.getFunction()
Deleted both *ssa folders from ir/implementation
Deleted the ValueCategory.qll file
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
7ef9bf6eea Fixed whitespace errors in PR 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
Andrei Diaconu
fc69c1201d Initial copy of C++ IR with some modifications 2019-08-28 12:25:13 +01:00
Tom Hvitved
16f40fd45a C#: Consolidate CFG tests 2019-08-23 15:25:01 +02:00
Anders Schack-Mulligen
2bea0a459a Java/C++/C#: Sync. 2019-08-23 11:34:17 +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
0801e51175 Merge pull request #1790 from jbj/tainttracking-cross-language
C++/C#/Java: Shared TaintTrackingImpl.qll
2019-08-22 14:17:23 +02:00
Jonas Jensen
ad9ee54b65 C++/C#/Java: defaultAdditionalTaintStep 2019-08-22 11:14:06 +02: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
e6ba282e05 C#: Revert a few changes 2019-08-22 09:26:13 +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
a2ffddec5f Merge pull request #1785 from jbj/dataflow-recursion-prevention-shared
C++/C#/Java: Pyrameterize ConfigurationRecursionPrevention
2019-08-21 15:56:50 +02:00
Jonas Jensen
25701f203d C++/C#/Java: Shared TaintTrackingImpl.qll
This file is now identical in all languages. Unifying this file led to
the following changes:
- The documentation spelling fixes and example from the C++ version
  were copied to the other versions and updated.
- The steps through `NonLocalJumpNode` from C# were abstracted into a
  `globalAdditionalTaintStep` predicate that's empty for C++ and Java.
- The `defaultTaintBarrier` predicate from Java is now present but empty
  on C++ and C#.
- The C++ `isAdditionalFlowStep` predicate on
  `TaintTracking::Configuration` no longer includes `localFlowStep`.
  That should avoid some unnecessary tuple copying.
2019-08-21 14:55:54 +02:00
Jonas Jensen
863bf523d6 C++/C#/Java: Autoformat 2019-08-21 13:24:01 +02:00
Jonas Jensen
fdd3b901f7 C/C#/Java: Share ConfigurationRecursionPrevention
This class was copy-pasted in all `DataFlowN.qll` files without using
the identical-files system to keep the copies in sync. The class is now
moved to the `DataFlowImplN.qll` files.

This also has the effect of preventing recursion through first data flow
library copy for C/C++. Such recursion has been deprecated for over a
year, and some forms of recursions are already ruled out by the library
implementation.
2019-08-21 13:04:10 +02:00
Jonas Jensen
6fc3a62edb C++/C#/Java: Change another caller of localFlow
There was also a use of `localFlowStep` in `DataFlowImplCommon` that
should now be `simpleLocalFlowStep`.
2019-08-21 10:20:15 +02:00
Jonas Jensen
ec2cc5a80e C#: Refactor how simpleLocalFlowStep is called
`localFlowStep` is no longer an alias because it should not have the
same QLDoc as `simpleLocalFlowStep`.
2019-08-21 10:05:54 +02:00