Skip to content

Commit a128383

Browse files
committed
C#/Java: Add some dfc-generated test cases.
1 parent 2a5dc20 commit a128383

File tree

9 files changed

+88
-41
lines changed

9 files changed

+88
-41
lines changed

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ static void Sink(object o) { }
293293
}
294294

295295
// Test synthetic fields
296-
public class K {
296+
public class K
297+
{
297298

298299
public object MyField;
299300

@@ -309,24 +310,42 @@ public class K {
309310

310311
public object GetMyFieldOnSyntheticField() => throw null;
311312

312-
public void M1() {
313+
public void M1()
314+
{
313315
var o = new object();
314316
SetMySyntheticField(o);
315317
Sink(GetMySyntheticField());
316318
}
317319

318-
public void M2() {
320+
public void M2()
321+
{
319322
var o = new object();
320323
SetMyNestedSyntheticField(o);
321324
Sink(GetMyNestedSyntheticField());
322325
}
323326

324-
public void M3() {
327+
public void M3()
328+
{
325329
var o = new object();
326330
SetMyFieldOnSyntheticField(o);
327331
Sink(GetMyFieldOnSyntheticField());
328332
}
329333

330334
static void Sink(object o) { }
331335
}
336+
337+
// Test content data flow provenance.
338+
public class L
339+
{
340+
public void M1()
341+
{
342+
var l = new Library();
343+
var o = new object();
344+
l.SetValue(o);
345+
Sink(l.GetValue());
346+
}
347+
348+
static void Sink(object o) { }
349+
}
350+
332351
}

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.cs_

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ namespace My.Qltest
1313
public static object StepArgReturnGenerated(object x) => throw null;
1414

1515
public static object StepArgReturnGeneratedIgnored(object x) => throw null;
16+
17+
public void SetValue(object o) => throw null;
18+
19+
public object GetValue() => throw null;
1620
}
1721
}
Binary file not shown.

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.expected

Lines changed: 50 additions & 36 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.ext.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extensions:
4343
- ["My.Qltest", "K", false, "GetMyNestedSyntheticField", "()", "", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField1].SyntheticField[MySyntheticField1.MyNestedSyntheticField]", "ReturnValue", "value", "manual"]
4444
- ["My.Qltest", "K", false, "SetMyFieldOnSyntheticField", "(System.Object)", "", "Argument[0]", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField2].Field[My.Qltest.K.MyField]", "value", "manual"]
4545
- ["My.Qltest", "K", false, "GetMyFieldOnSyntheticField", "()", "", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField2].Field[My.Qltest.K.MyField]", "ReturnValue", "value", "manual"]
46+
- ["My.Qltest", "Library", false, "SetValue", "(System.Object)", "", "Argument[0]", "Argument[this].SyntheticField[X]", "value", "dfc-generated"]
47+
- ["My.Qltest", "Library", false, "GetValue", "()", "", "Argument[this].SyntheticField[X]", "ReturnValue", "value", "dfc-generated"]
4648

4749
- addsTo:
4850
pack: codeql/csharp-all

java/ql/test/library-tests/dataflow/external-models/C.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void fooLibrary() {
5454
// The summary for the parameter is ignored, because it is generated and
5555
// because there is a manual neutral summary model for this callable.
5656
lib.apiStepArgQualGeneratedIgnored(arg1);
57+
58+
lib.getValue();
5759
}
5860

5961
void fooPossibleLibraryDispatch(Library lib) {

java/ql/test/library-tests/dataflow/external-models/steps.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ invalidModelRow
1111
| C.java:44:32:44:35 | arg1 | C.java:44:5:44:36 | apiStepArgResGenerated(...) |
1212
| C.java:50:45:50:48 | arg2 | C.java:50:5:50:49 | apiStepArgResGeneratedIgnored(...) |
1313
| C.java:52:33:52:36 | arg1 | C.java:52:5:52:7 | lib [post update] |
14-
| C.java:62:12:62:15 | arg1 | C.java:62:5:62:16 | id(...) |
14+
| C.java:58:5:58:7 | lib | C.java:58:5:58:18 | getValue(...) |
15+
| C.java:64:12:64:15 | arg1 | C.java:64:5:64:16 | id(...) |

java/ql/test/library-tests/dataflow/external-models/steps.ext.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extensions:
1616
- ["my.qltest.external", "Library", False, "apiStepArgQualGenerated", "(Object)", "", "Argument[0]", "Argument[this]", "taint", "df-generated"]
1717
- ["my.qltest.external", "Library", False, "apiStepArgQualGeneratedIgnored", "(Object)", "", "Argument[0]", "Argument[this]", "taint", "df-generated"]
1818
- ["my.qltest.external", "Library", False, "id", "(Object)", "", "Argument[0]", "ReturnValue", "taint", "df-generated"]
19+
- ["my.qltest.external", "Library", False, "getValue", "()", "", "Argument[this]", "ReturnValue", "taint", "dfc-generated"]
1920
- addsTo:
2021
pack: codeql/java-all
2122
extensible: neutralModel

java/ql/test/library-tests/dataflow/external-models/stubs/Library.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public Object apiStepArgQualGeneratedIgnored(Object x) {
2020
public Object id(Object x) {
2121
return null;
2222
}
23+
24+
public Object getValue() {
25+
return null;
26+
}
2327
}

0 commit comments

Comments
 (0)