Skip to content

Commit 6f74387

Browse files
authored
Merge pull request github#17521 from michaelnebel/modelgen/moreimprovements
C#/Java: Content based model generation improvements.
2 parents 4513643 + baae8d0 commit 6f74387

40 files changed

+626
-251
lines changed

csharp/ql/src/utils/modelgenerator/CaptureContentSummaryModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
import internal.CaptureModels
1010

1111
from DataFlowSummaryTargetApi api, string flow
12-
where flow = ContentSensitive::captureFlow(api)
12+
where flow = ContentSensitive::captureFlow(api, _)
1313
select flow order by flow
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture mixed neutral models.
3+
* @description Finds neutral models to be used by other queries.
4+
* @kind diagnostic
5+
* @id cs/utils/modelgenerator/mixed-neutral-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSummaryTargetApi api, string noflow
12+
where noflow = captureMixedNeutral(api)
13+
select noflow order by noflow
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture mixed summary models.
3+
* @description Finds applicable summary models to be used by other queries.
4+
* @kind diagnostic
5+
* @id cs/utils/modelgenerator/mixed-summary-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSummaryTargetApi api, string flow
12+
where flow = captureMixedFlow(api, _)
13+
select flow order by flow

csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ module ModelGeneratorInput implements ModelGeneratorInputSig<Location, CsharpDat
131131

132132
Callable lift() { result = lift }
133133

134-
predicate isRelevant() { relevant(this) }
134+
predicate isRelevant() {
135+
relevant(this) and
136+
not hasManualSummaryModel(this)
137+
}
135138
}
136139

137140
/**

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

csharp/ql/test/utils/modelgenerator/dataflow/CaptureContentSummaryModels.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import utils.modelgenerator.internal.CaptureModels
33
import TestUtilities.InlineMadTest
44

55
module InlineMadTestConfig implements InlineMadTestConfigSig {
6-
string getCapturedModel(Callable c) { result = ContentSensitive::captureFlow(c) }
6+
string getCapturedModel(Callable c) { result = ContentSensitive::captureFlow(c, _) }
77

88
string getKind() { result = "contentbased-summary" }
99
}

0 commit comments

Comments
 (0)