Граф коммитов

1167 Коммитов

Автор SHA1 Сообщение Дата
AndreiDiaconu1 43accd37e1 Address PR comments 2019-09-16 15:42:45 +01:00
Calum Grant 8eeded5982 C#: Handle nameof(A.B) where A.B is a nested namespace. 2019-09-16 15:12:10 +01:00
AndreiDiaconu1 fcb3d99351 C# IR: Fix for init 2019-09-16 11:57:37 +01:00
Tom Hvitved 4f897b2628 C#: Address review comments 2019-09-16 10:45:37 +02:00
Tom Hvitved f5cae9b6ea
Merge pull request #1881 from aschackmull/java/pathgraph-nodes
Java/C++/C#: Add nodes predicate to PathGraph.
2019-09-13 10:32:47 +02:00
Calum Grant b7db15646c
Merge pull request #1858 from AndreiDiaconu1/ircsharp-continue
C# IR: Add support for `ContinueStmt`
2019-09-12 17:37:01 +01:00
AndreiDiaconu1 e55f16d990 Fix comment 2019-09-12 13:57:28 +01:00
AndreiDiaconu1 91fdfd48e5 Fixed CP problem 2019-09-12 13:09:49 +01:00
Tom Hvitved 5070270605 C#: Fix CFG for nested `finally` blocks 2019-09-12 11:44:04 +02:00
Tom Hvitved b9fa837963 C#: Add new CFG test for try/finally 2019-09-12 11:44:04 +02:00
Tom Hvitved 3d32f3d173 C#: Restructure existing CFG tests for try/finally 2019-09-12 11:44:04 +02:00
AndreiDiaconu1 47120bc923 PR fixes 2019-09-12 10:34:00 +01:00
Calum Grant e330d5a6c6
Merge pull request #1549 from hvitved/csharp/cfg/loop-unrolling
C#: Loop unrolling for `foreach` statements
2019-09-12 10:24:26 +01:00
AndreiDiaconu1 420abbf3dc C# IR: Support for `ContinueStmt`
Added support for continue stmt.
Minimal refactoring of the `TranslatedSpecificJump` classes.
Added a new test file, `jumps.cs` and updated the expected output.
2019-09-12 10:01:48 +01:00
Anders Schack-Mulligen 6299625b3d C#: Adjust qltest expected output. 2019-09-12 11:00:49 +02:00
Anders Schack-Mulligen 95e2f162d9 Java/C++/C#: Adjust toString of empty accesspath. 2019-09-12 11:00:49 +02:00
Anders Schack-Mulligen 0a4b15d40b Java/C++/C#: Add nodes predicate to PathGraph. 2019-09-12 11:00:49 +02:00
Tom Hvitved 8f3f9406e2 C#: Early identification of duplicate extraction 2019-09-11 20:47:20 +02:00
Calum Grant b85823bec5
Merge pull request #1857 from AndreiDiaconu1/ircsharp-forstmt
C# IR: More support for `ForStmt`s
2019-09-11 13:11:05 +01:00
AndreiDiaconu1 195b99cf96 PR fixes 2019-09-11 09:54:01 +01:00
semmle-qlci 05247849b0
Merge pull request #1913 from xiemaisi/csharp/update-a-qlref
Approved by hvitved
2019-09-10 16:04:19 +01:00
Max Schaefer ea81531a7b C#: Update a `.qlref`.
This currently relies on the fact that qltest includes `ql/csharp/ql/src/Metrics` in addition to `ql/csharp/ql/src` on its search path when run internally, which is inconsistent with the other languages. Since this is the only test that relies on it, I'd like to update it and get rid of the extra search root eventually.
2019-09-10 13:01:04 +01:00
AndreiDiaconu1 442c9f2cc8 Delete useless file 2019-09-10 09:52:35 +01:00
AndreiDiaconu1 241a40c145 C# IR: Initializers
Add support for collection initializers.
Instead of using `AssignExpr` for the translation of object initializers, `MemberInitializer` is now used.
2019-09-10 09:32:00 +01:00
AndreiDiaconu1 0528d8ef39 C# IR: Object creation refactoring
The way object creation was translated has been changed: now creations are treated as expressions.
The main motivation for this was the inability to have creation expressions as arguments to
function calls (a test case has been added to showcase this).
All code that dealt with creation expressions has been moved from `TranslatedInitialization.qll` to `TranslatedExpr.qll`.
Some light refactoring has also been done, mainly removing code that was useless after the changes mentioned above.
2019-09-10 09:20:21 +01:00
AndreiDiaconu1 d9f3c14c9c C# IR: Add support for multiple decls and updates
Added support for multiple declarations and updates in a for stmt.
Added test cases and updated the expected output.
2019-09-10 09:17:41 +01:00
Tom Hvitved 41cd13a637 C#: Update expected test output 2019-09-10 09:17:50 +02:00
Calum Grant 79a750dfaf
Merge pull request #1845 from AndreiDiaconu1/ircsharp-compiler-generated
C# IR: Framework for translating compiler generated elements
2019-09-09 15:42:07 +01:00
Tom Hvitved 170621d1cc C#: Address review comments 2019-09-09 13:38:23 +02:00
AndreiDiaconu1 53ebe23db6 Better retrieval for the `GetEnumerator` call 2019-09-09 12:33:19 +01:00
Tom Hvitved 77d7db323d
Merge pull request #1895 from calumgrant/cs/date-queries
C#: Tidy up cs/unsafe-year-construction and cs/mishandling-japanese-era
2019-09-09 11:24:49 +02:00
Jonas Jensen d51e5212fb Merge remote-tracking branch 'upstream/master' into dataflow-TTwo
Conflicts:
      cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll
      cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll
      cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll
      cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll
      cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplLocal.qll
      cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll
      cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl2.qll
      cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl3.qll
      cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl4.qll
      cpp/ql/test/library-tests/dataflow/fields/flow.expected
      csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImpl.qll
      csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImpl2.qll
      csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImpl3.qll
      csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImpl4.qll
      csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImpl5.qll
      java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl.qll
      java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl2.qll
      java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl3.qll
      java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl4.qll
      java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl5.qll
2019-09-08 21:08:43 +02:00
AndreiDiaconu1 320cd6b96c More PR fixes 2019-09-06 18:10:54 +01:00
AndreiDiaconu1 765414430d More PR fixes 2019-09-06 18:10:54 +01:00
AndreiDiaconu1 9ecbb4a3f3 More fixes for the PR comments 2019-09-06 18:10:54 +01:00
AndreiDiaconu1 fe3645f26d Fix some PR comments 2019-09-06 18:09:15 +01:00
AndreiDiaconu1 db213bbf80 Fixed sanity checks
The foreach was erroneously labelling the `True` and `False` edges as backedges.
Added a case for the compiler generated while in the predicate `getInstructionBackEdgeSuccessor/2`
from the file `IRConstruction.qll` so that only the edges from inside the body are labeled as back edges.
2019-09-06 18:09:15 +01:00
AndreiDiaconu1 46d7b9e3bf Lock stmt
Added support for the lock stmt
Added a test case and updated the expected output
2019-09-06 18:09:15 +01:00
AndreiDiaconu1 4dd548bfa2 Foreach stmt
Addded support for the foreach stmt (for now only the "canonical" desugaring).
Added a test and updated the expected output.
2019-09-06 18:09:15 +01:00
AndreiDiaconu1 a5ec763035 Delegate creation and call
Added support for delegate creation and call.
Added a test case and updated the expected output.
2019-09-06 18:08:03 +01:00
AndreiDiaconu1 331707f3a3 Framework for the translation of compiler elements
Added a framework for the translation of compiler generated elements, so that the process of adding a new desugaring process is almost mechanical.
The files in `internal` serve as the superclasses for all the compiler generated elements.
The file `Common.qll` captures common patterns for the compiler generated code to improve code sharing (by pattern I mean an element that appears in multiple desugarings). For example the `try...finally` pattern appears in the desugaring process of both the `lock` and the `foreach` stmts, so a class the provides a blueprint for this pattern is exposed. Several other patterns are present.
The expected output has also been updated (after a rebase) and it should be ignored.
2019-09-06 18:08:03 +01:00
AndreiDiaconu1 80b7512fe2 Initial restructure
The `raw/internal` folder has been restructured to better enhance code sharing between compiler generated elements and AST generated elements.
The translated calls classes have been refactored to better fit the C# library.
A new folder has been added, `common` that provides blueprints for the classes that deal with translations of calls, declarations, exprs and conditions.
Several `TranslatedX.qll` files have been modified so that they use those blueprint classes.
2019-09-06 18:08:03 +01:00
Calum Grant f9b99ae245 C#: Adjust date query severity and add precisions. Tidy up tags. 2019-09-06 16:44:29 +01:00
Anders Schack-Mulligen 343230402a C#: Autoformat. 2019-09-06 09:04:16 +02:00
Jonas Jensen 9c9b7ac651 C#/C++/Java: Revert AccessPathNil.toString changes
This caused too many `*.expected` files to change, also in our internal
repo.
2019-09-02 15:59:36 +02:00
Jonas Jensen a98992f0f9 C#/C++/Java: distinguish toString of nil from cons 2019-09-02 14:22:03 +02:00
Jonas Jensen cdede8744f C#/C++/Java: Prettier PartialAccessPath.toString 2019-09-02 14:05:50 +02:00
Jonas Jensen c3bc9f8575 C#/C++/Java: Unbreak partial data flow support
Partial data flow had a semantic merge conflict with this branch. The
problem is that partial data flow doesn't (and shouldn't) cause the
initial pruning steps to run, but the length-2 access paths depend on
the `consCand` information that comes from that initial pruning. The
solution is to restore the old `AccessPath` class, now called
`PartialAccessPath` for use only by partial data flow.

With this change, partial data flow will in some cases allow more field
flow than non-partial data flow.
2019-09-02 14:02:39 +02:00
Jonas Jensen dec0c3a0ee C#/C++/Java: Make AccessPath abstract
This was requested by @hvitved in code review. There is no difference in
the generated DIL.
2019-09-02 13:14:30 +02:00
Jonas Jensen b1be123e31 C#/C++/Java: Prettier AccessPath.toString
The `ppReprType` predicate should now be `none()` instead of `result=""`
to signal that there is nothing to print. That seems clearer to me.
2019-09-02 13:14:20 +02:00
Jonas Jensen dbe8034e04 C#: Accept test results 2019-09-02 13:14:17 +02:00
Jonas Jensen b2c94cc6b4 C++/C#/Java: Restore the AccessPathCons class 2019-09-02 13:14:13 +02:00
Jonas Jensen fbe34015f3 C++/C#/Java: AccessPath class names reflect length
One -> ConsNil
Two -> ConsCons
2019-09-02 13:13:59 +02:00
Jonas Jensen e8006bb2cc C++/C#/Java: data flow AccessPath up to length 2
This commit does not include updates to test results.
2019-09-02 13:13:46 +02:00
semmle-qlci 0cf872ed32
Merge pull request #1846 from hvitved/csharp/autoformat
Approved by jbj
2019-09-02 08:31:43 +01:00
Tom Hvitved 675255755b C#: Speedup `Completion::isValidFor()` 2019-09-01 10:34:52 +02:00
Tom Hvitved 508055fdc8 C#: Add a few `pragma[nomagic]` 2019-09-01 10:34:51 +02:00
Tom Hvitved 1e7ee8ddad C#: Loop unrolling for `foreach` statements 2019-09-01 10:34:51 +02:00
Tom Hvitved 1bfef706e2 C#: Add loop unrolling tests 2019-09-01 10:34:51 +02:00
Tom Hvitved bb735c0220 C#: Teach guards library about collections 2019-09-01 10:34:51 +02:00
semmle-qlci 00fe4734ac
Merge pull request #1850 from hvitved/csharp/remove-ref-equal
Approved by calumgrant
2019-09-01 09:31:50 +01:00
yh-semmle f54545522e
Merge pull request #1759 from aschackmull/java/flow-exploration
Java/C++/C#: Add support for dataflow exploration by partial paths.
2019-08-30 17:00:17 -04:00
Tom Hvitved 6dc869d5c6 C#: Remove reference equality 2019-08-30 15:52:42 +02:00
Tom Hvitved 3e716bf806
Merge pull request #1749 from calumgrant/cs/extractor-tidy
C#: Refactor extractor trap generation code
2019-08-30 15:44:35 +02:00
Tom Hvitved c9275fdc0a
Merge pull request #1692 from calumgrant/cs/roslyn-3.2
C#: Upgrade to Roslyn 3.2
2019-08-30 15:09:11 +02:00
Anders Schack-Mulligen 5e6326d1d5 Java/C++/C#: Add support for dataflow exploration by partial paths. 2019-08-30 14:32:55 +02:00
semmle-qlci 394563de43
Merge pull request #1807 from hvitved/csharp/dataflow/barrier-guard
Approved by calumgrant
2019-08-30 12:40:25 +01:00
Calum Grant c7b685b3b8 C#: Fix changed qltest. 2019-08-30 11:47:43 +01:00
Calum Grant 611af1e2c2 C#: Upgrade to Roslyn 3.2. 2019-08-30 11:47:43 +01:00
Calum Grant ec61877ce8
Merge pull request #1805 from hvitved/csharp/dataflow/nested-fields
C#: Nested field flow
2019-08-30 10:26:10 +01:00
Calum Grant 0129b42c54 C#: Address review comments. 2019-08-30 10:11:01 +01:00
Calum Grant 7df90f13ed C#: Address review comments. Tidy up tuple generation, consolidating code and use run-time type information instead of FirstParam/NextParam. 2019-08-30 10:11:01 +01:00
Calum Grant 40f56ff4b3 C#: Code tidy. Rename variables, delete dead code, format whitespace, improve comments. 2019-08-30 10:11:01 +01:00
Calum Grant b3d5e405a6 C#: Fix violations 2019-08-30 10:11:01 +01:00
Calum Grant 97522c506e C#: Add more CIL consistency tests. 2019-08-30 10:11:01 +01:00
Calum Grant b776421602 C#: Fix up tests. Fix cil_class, and add locations for constructed methods and types. 2019-08-30 10:11:01 +01:00
Calum Grant 02fd51ae61 C#: Resolve merge conflicts. 2019-08-30 10:11:00 +01:00
Calum Grant b500a02b1e C#: Compare CIL entities directly by handle rather than by label.
C#: Remove IDs from the CIL extractor and make consistent with C# extractor.
C#: Fix method collisions.
2019-08-30 10:11:00 +01:00
Calum Grant 685c494bcb C#: Make the trap compression algorithm configurable. 2019-08-30 10:11:00 +01:00
Calum Grant fe7e90e25a C#: Remove the tuples from the C# extractor. 2019-08-30 10:11:00 +01:00
Calum Grant 486c192dda C#: Refactoring expression and statement population. 2019-08-30 10:11:00 +01:00
Calum Grant e41e8d6547 C#: Remove ITrapBuilder in favour of TextWriter. 2019-08-30 10:00:06 +01:00
Calum Grant aeb38a1757 C#: Refactoring tuple writing to remove Tuple intermediate object and write straight to trap file. 2019-08-30 10:00:06 +01:00
Calum Grant bd1b0018b0 C#: Rename some methods. 2019-08-30 10:00:06 +01:00
Calum Grant 58e6d236ff C#: Tidy up CommentProcessing. 2019-08-30 10:00:06 +01:00
Tom Hvitved 9f59e385d1 C#: Autoformat 2019-08-30 09:53:50 +02:00
Tom Hvitved 6e7ef66642 C#: Revert to using `GuardedDataFlowNode` in `TaintedPath.qll` 2019-08-30 09:37:23 +02:00
Tom Hvitved 751985dcf2 C#: Address review comments 2019-08-30 09:37:23 +02:00
Tom Hvitved ae5fb7f330 C#: Introduce `BarrierGuard`s 2019-08-30 09:37:16 +02:00
Calum Grant 4dd4167a5a C#: Update test output (following merge). 2019-08-29 18:22:37 +01:00
Calum Grant 83d1e0eaa6 C#: Name DotNet::Namespace a declaration. 2019-08-29 18:12:58 +01:00
Calum Grant 83ab044a73 C#: Update expected test output. 2019-08-29 18:12:58 +01:00
Calum Grant dfbb1946d3 C#: Minor edits 2019-08-29 18:11:00 +01:00
Calum Grant 5613769654 C#: Add NamespaceAccess, and make namespaces declarations. 2019-08-29 18:11:00 +01:00
Calum Grant 0e62377dd2 C#: Treat _ as an ordinary variable in a foreach. 2019-08-29 18:11:00 +01:00
Calum Grant 8aeeec01ff C#: Add namespace_access_expr because of nameof(Namespace) 2019-08-29 18:11:00 +01:00
Calum Grant ae36359058 C#: Fix typementions of arrays. 2019-08-29 18:11:00 +01:00
Tom Hvitved 982f90dc2b C#: Refactor local data flow step relations 2019-08-29 13:35:19 +02:00
semmle-qlci f980d20d6d
Merge pull request #1809 from hvitved/csharp/cfg/tests
Approved by calumgrant
2019-08-29 11:35:21 +01:00
Calum Grant d2bee79370
Merge pull request #1600 from AndreiDiaconu1/ircsharp
C#: Initial port of IR for C#
2019-08-29 09:26:34 +01:00
AndreiDiaconu1 deeff07322 Fixed unused predicate error 2019-08-28 15:50:39 +01:00
AndreiDiaconu1 489dbe1d01 Fixed errors
Added some new classes for built in operations that for the moment
have no effect (added to remove errors)
2019-08-28 14:23:42 +01:00
AndreiDiaconu1 05ae04df72 Synced files 2019-08-28 12:30:17 +01:00
AndreiDiaconu1 66948b4f57 Fixed PR errors 2019-08-28 12:25:14 +01:00
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
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 c9ea5ad9a3 C#/Java: Remove `cached` from wrapper predicate 2019-08-21 09:43:13 +02:00
Jonas Jensen 4b7813b98e C++/C#/Java: Split localFlowStep predicate in two
There's now a `localFlowStep` predicate for use directly in queries and
other libraries and a `simpleLocalFlowStep` for use only by the global
data flow library. The former predicate is intended to include field
flow, but the latter may not.

This will let Java and C# (and possibly C++ IR) avoid getting two kinds
of field flow at the same time, both from SSA and from the global data
flow library. It should let C++ AST add some form of field flow to
`localFlowStep` without making it an input to the global data flow
library.
2019-08-21 09:27:01 +02:00
Anders Schack-Mulligen 9150682ada
Merge pull request #1757 from jbj/pyrameterized-taint
C++: Use pyrameterized modules for TaintTracking
2019-08-20 16:33:22 +02:00
Calum Grant 35017786cf
Merge pull request #1739 from hvitved/csharp/ssa/delegate-call-source
C#: Search from delegate creation in `delegateCallSource()`
2019-08-20 15:16:20 +01:00
Tom Hvitved 7ab9c8b90d Java/C++/C#: `flowCandFwdRead()` refactor 2019-08-20 14:44:04 +02:00
Tom Hvitved 80e91cceb1 C#: Disable field flow for `cs/inappropriate-encoding` 2019-08-20 13:59:46 +02:00
Tom Hvitved 14378ee41a Java/C++/C#: Remove some `unbind()` calls from shared data flow implementation 2019-08-20 13:59:01 +02:00
Jonas Jensen 7c4938c035 C#: Get rid of `TaintTrackingUtil.qll` 2019-08-20 13:56:13 +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 a0c834c83d Java/C++/C#: Improve data flow join orders for field flow 2019-08-20 10:14:08 +02:00
Tom Hvitved 1e46509a2a C#: Use `TaintTracking2` in `cs/inappropriate-encoding` 2019-08-19 17:18:49 +02:00
Tom Hvitved 2a2e07d2fc C#: Avoid recomputation in last data flow stage
Avoid recomputing the `ControlFlowReachabilityConfiguration` predicates, as well
as `DispatchCall::getStaticTarget()`.
2019-08-19 17:17:47 +02:00
Anders Schack-Mulligen 6ff4fe38ec Java/C++/C#: Add field flow support for stores in nested fields. 2019-08-19 14:41:06 +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
Anders Schack-Mulligen 1938ac4937 Java/C++/C#: Sync. 2019-08-14 10:32:15 +02:00
Anders Schack-Mulligen 411bc16f44 Java/C++/C#: Address review comment. 2019-08-13 16:57:48 +02:00
Anders Schack-Mulligen 9e902066ad Java/C++/C#: Elaborate qldoc. 2019-08-13 16:57:48 +02:00
Anders Schack-Mulligen 4550175b16 Java/C++/C#: Add support for BarrierGuards. 2019-08-13 16:57:48 +02:00
Tom Hvitved 36043d04bd
Merge pull request #1729 from xiemaisi/data-flow-nodes-location
Java/C++/C#: Provide path-node locations via `hasLocationInfo`, not `getLocation`.
2019-08-13 12:22:59 +02:00
Tom Hvitved e4bd1980ab C#: Search from delegate creation in `delegateCallSource()` 2019-08-13 10:22:29 +02: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
Max Schaefer 485d4269a0 C#: Fix use of `PathNode.getLocation()`. 2019-08-12 15:04:37 +01:00
Max Schaefer eb8087f4ea Java/C++/C#: Provide path-node locations via `hasLocationInfo`, not `getLocation`. 2019-08-12 12:52:30 +01:00
semmle-qlci e890aba4fe
Merge pull request #1712 from hvitved/csharp/remove-nomagic
Approved by calumgrant
2019-08-12 10:59:10 +01:00
Tom Hvitved 98ab2b26dc C#: Fix bad join-order in `guardImpliesNotEqual()` 2019-08-12 09:50:17 +02: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 c1604caa31 C#: Remove two `pragma[nomagic]` 2019-08-07 16:04:23 +02:00
Tom Hvitved 96e1732f94 C#: Address review comments 2019-08-07 10:41:43 +02:00
Tom Hvitved 6749bbd438 C#: Make use of extra data flow copies 2019-08-07 10:41:43 +02:00
Tom Hvitved 081ee9944d C#: Add more copies of the data flow library 2019-08-07 10:41:39 +02:00
yh-semmle 033879f5a6
Merge pull request #1639 from aschackmull/java/in-out-barriers
Java/C++/C# DataFlow: Add support for in/out barriers on sources and sinks.
2019-08-07 01:07:19 -04: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
Anders Schack-Mulligen a80cb262fc Java/C++/C#: Elaborate qldoc. 2019-08-05 16:28:25 +02:00
Anders Schack-Mulligen 9ebb83497d Java/C++/C#: Fix small mistake. 2019-08-05 15:34:12 +02:00
Anders Schack-Mulligen 2dc83c539c Java/C++/C#: Sync dataflow. 2019-08-05 12:07:32 +02:00
Calum Grant 3e143093f0
Merge pull request #1475 from hvitved/csharp/remove-file
C#: Remove unused `PasswordInConfigurationFile.config`
2019-08-05 10:29:50 +01:00
Jonas Jensen 73d8bf38a9
Merge pull request #1680 from aschackmull/cookbook/autoformat
Cookbook examples: Autoformat
2019-08-05 10:24:56 +02: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
Anders Schack-Mulligen 40f2cec0de C#: Autoformat cookbook examples. 2019-08-02 15:30:32 +02:00
Calum Grant 169dbf1be3 C#: Remove rule CA1022, which caused the analyzer to crash, generating a compilation warning (and possibly, instability). 2019-08-02 12:14:03 +01:00
semmle-qlci 108e5bc431
Merge pull request #1675 from hvitved/csharp/xss-path-problem
Approved by lukecartey
2019-08-02 04:17:03 +01:00
Tom Hvitved b7d6165d42 C#: Convert `cs/web/xss` to a `path-problem` 2019-08-01 15:58:57 -07:00
semmle-qlci 1d806971ed
Merge pull request #1634 from aibaars/cookbook
Approved by aschackmull, dave-bartolomeo, hvitved, markshannon, xiemaisi, yh-semmle
2019-07-31 14:31:28 +01: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 902825f8ac
Merge pull request #1564 from calumgrant/cs/no-logger-writethrough
C#: Disable logger AutoFlush
2019-07-29 15:20:00 +00:00
Arthur Baars ccde7cf6cf Add @id to example queries 2019-07-26 17:47:11 +02:00
Arthur Baars bdce7d07c1 Move 'snippet' queries to 'snippets' folders 2019-07-26 17:47:11 +02:00
Arthur Baars 30860daac4 Add cookbook queries 2019-07-26 17:47:11 +02:00
Anders Schack-Mulligen 6d022aa359 Java/C++/C#: Sync dataflow. 2019-07-26 13:17:12 +02:00
Anders Schack-Mulligen cd8d16183c Java/CPP/C#: Sync dataflow. 2019-07-22 15:41:37 +02:00
Felicity Chapman cb48af7395 Update Python and C# help for commented-out code to use common qhelp 2019-07-15 09:26:17 +01:00
Calum Grant ce12312ff2 C#: Disable the write-through of the logger, as this is a theoretical slowdown, and results in less readable log files when multiple extractors are running concurrently. 2019-07-08 15:58:49 +01:00
Tom Hvitved f56c17fc77 C#: Fix bad join-orders in `lastNonRec()` 2019-07-05 07:21:34 +02:00
Tom Hvitved e6c258c6ba C#: Restructure `Completion::isValidFor()` 2019-07-05 07:21:34 +02: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 349e0e8e62 C#: Address more review comments 2019-07-04 16:46:01 +02:00
Tom Hvitved 421e75d4c1 C#: Address review comments 2019-07-04 11:57:48 +02:00
Tom Hvitved b6bbe1a5c0 C#: Add DB upgrade script 2019-07-02 14:01:41 +02:00
Tom Hvitved 16b6791914 C#: Minor performance rewrite 2019-07-02 13:11:27 +02:00
Tom Hvitved 9a24d3a69c C#: Remove libraries and queries related to version history
The VCS relations are no longer populated, so there is no reason to keep them,
and the queries/libraries that use the relations.
2019-07-02 10:43:38 +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
Tom Hvitved e6e606232d C#: Address review comments 2019-07-01 09:37:15 +02:00
semmle-qlci ae3a48db58
Merge pull request #1510 from hvitved/csharp/date-queries-remove-precision
Approved by calumgrant
2019-07-01 08:28:08 +01:00
yh-semmle a0dc84010a
Merge pull request #1518 from Semmle/rc/1.21
Merge rc/1.21 into master
2019-06-28 13:52:18 -04: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
Tom Hvitved f91e460869 C#: Introduce inherited CFG completions
When completions are inherited by elements inside `finally` blocks, we previously
threw away the underlying completion. For example, in

```
try
{
    if (b)
        throw new Exception();
}
finally
{
    if (b)
        ...
}
```

the completions for `b` inside the `finally` block are `true` and `throw(Exception)`,
where the latter is inherited from the `try` block, with an underlying `false`
completion. Throwing away the `false` completion meant that we were unable to prune
the `false` edge (Boolean CFG splitting).
2019-06-28 15:41:49 +02:00
Tom Hvitved 8d7ea2f49f C#: Add CFG test that mixes Boolean/finally/catch splitting 2019-06-28 15:41:49 +02:00
Calum Grant 8130342062
Merge pull request #1520 from hvitved/csharp/mono-tracing
C#: Generalize `mono` pattern in tracer config
2019-06-28 14:21:35 +01:00
Calum Grant 4d383001ac C#: Address review comment 2019-06-28 14:17:16 +01:00
Calum Grant a5543699b2
Merge pull request #1460 from hvitved/csharp/cfg-last
C#: Refactor `last` predicate
2019-06-28 14:13:43 +01:00
Tom Hvitved 3d4316da1c C#: Address review comments 2019-06-28 13:00:18 +02:00
Tom Hvitved db565c5a88 C#: Remove false positives in `cs/constant-condition` 2019-06-28 11:50:53 +02:00
Tom Hvitved 4da7a17f4b C#: Add more tests for `cs/constant-condition` 2019-06-28 11:25:18 +02:00
Tom Hvitved 051ec83ae0 C#: Generalize `mono` pattern in tracer config 2019-06-28 09:16:38 +02:00
Calum Grant 2504754e8e C#: Remove use of deprecated predicates. 2019-06-27 15:35:37 +01:00
Tom Hvitved 481bf77d5f CIL: Speedup consistency tests
- Make `InstructionViolation` abstract to avoid computing `getInstructionsUpTo()`
  for all instructions in the database.
- Enable `consistency.ql`, which reports all consistency violations, and remove
  all other specialized tests.
2019-06-27 13:40:07 +02:00
Tom Hvitved 04279531e7 C#: Remove `@precision` for new date queries
Removing the `@precision` annotation until we know how precise these queries
actually are for projects on LGTM.com.
2019-06-27 10:33:27 +02:00
Tom Hvitved b6cf13510c C#: Update `@name` for two queries 2019-06-27 10:22:56 +02:00
semmle-qlci 1c25e17812
Merge pull request #1505 from hvitved/csharp/autoformat
Approved by calumgrant
2019-06-27 08:03:58 +01:00
semmle-qlci f58c7cc79c
Merge pull request #1446 from hvitved/csharp/cached-stages
Approved by calumgrant
2019-06-27 08:03:24 +01:00
Calum Grant 76454ed68a C#: Fix formatting of arrays and NullableTypes 2019-06-26 20:24:56 +01:00
Calum Grant abf43dabe5 C#: Address review comments. Fix up toStringWithTypes(), and deprecate predicates in TypeParameterConstraints. 2019-06-26 20:24:56 +01:00
Calum Grant 620ecc8128 C#: Address review comments part 1. 2019-06-26 20:24:56 +01:00
Calum Grant 35ecb948fc C#: Fix qltests. 2019-06-26 20:24:55 +01:00
Calum Grant abe961f094 C#: Remove disabled and not-applicable nullability annotations since they can be deduced. 2019-06-26 20:24:55 +01:00