Skip to content

Commit 4a5c9f0

Browse files
authored
Merge pull request #17007 from michaelnebel/shared/neutralimplementation
C#/Java/Go: Neutrals are split into separate classes.
2 parents 3c6459e + 2796597 commit 4a5c9f0

File tree

14 files changed

+159
-145
lines changed

14 files changed

+159
-145
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -953,21 +953,3 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
953953
interpretSummary(this, _, _, _, provenance, _)
954954
}
955955
}
956-
957-
// adapter class for converting Mad neutrals to `NeutralCallable`s
958-
private class NeutralCallableAdapter extends NeutralCallable {
959-
string kind;
960-
string provenance_;
961-
962-
NeutralCallableAdapter() {
963-
// Neutral models have not been implemented for CPP.
964-
none() and
965-
exists(this) and
966-
exists(kind) and
967-
exists(provenance_)
968-
}
969-
970-
override string getKind() { result = kind }
971-
972-
override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
973-
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ private predicate interpretSummary(
556556
)
557557
}
558558

559-
private predicate interpretNeutral(UnboundCallable c, string kind, string provenance) {
559+
predicate interpretNeutral(UnboundCallable c, string kind, string provenance) {
560560
exists(string namespace, string type, string name, string signature |
561561
neutralModel(namespace, type, name, signature, kind, provenance) and
562562
c = interpretElement(namespace, type, false, name, signature, "")
@@ -613,18 +613,6 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
613613
}
614614
}
615615

616-
// adapter class for converting Mad neutrals to `NeutralCallable`s
617-
private class NeutralCallableAdapter extends NeutralCallable {
618-
string kind;
619-
string provenance_;
620-
621-
NeutralCallableAdapter() { interpretNeutral(this, kind, provenance_) }
622-
623-
override string getKind() { result = kind }
624-
625-
override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
626-
}
627-
628616
/**
629617
* A callable where there exists a MaD sink model that applies to it.
630618
*/

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ private import semmle.code.csharp.dataflow.internal.ExternalFlow
1616
module Input implements InputSig<Location, DataFlowImplSpecific::CsharpDataFlow> {
1717
class SummarizedCallableBase = UnboundCallable;
1818

19+
predicate neutralElement(SummarizedCallableBase c, string kind, string provenance, boolean isExact) {
20+
interpretNeutral(c, kind, provenance) and
21+
// isExact is not needed for C#.
22+
isExact = false
23+
}
24+
1925
ArgumentPosition callbackSelfParameterPosition() { result.isDelegateSelf() }
2026

2127
ReturnKind getStandardReturnValueKind() { result instanceof NormalReturnKind }
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import shared.FlowSummaries
22
import semmle.code.csharp.dataflow.internal.ExternalFlow
33

4-
final private class NeutralCallableFinal = NeutralCallable;
5-
6-
class RelevantNeutralCallable extends NeutralCallableFinal {
7-
final string getCallableCsv() { result = getSignature(this) }
4+
module R implements RelevantNeutralCallableSig<NeutralSummaryCallable> {
5+
class RelevantNeutralCallable extends NeutralSummaryCallable {
6+
final string getCallableCsv() { result = getSignature(this) }
7+
}
88
}
99

1010
class RelevantSourceCallable extends SourceCallable {
@@ -16,5 +16,5 @@ class RelevantSinkCallable extends SinkCallable {
1616
}
1717

1818
import TestSummaryOutput<IncludeSummarizedCallable>
19-
import TestNeutralOutput<RelevantNeutralCallable>
19+
import TestNeutralOutput<NeutralSummaryCallable, R>
2020
import External::TestSourceSinkOutput<RelevantSourceCallable, RelevantSinkCallable>

csharp/ql/test/utils/modelgenerator/dataflow/CaptureNeutralModels.ext.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ extensions:
44
extensible: neutralModel
55
data:
66
- [ "Models", "ManuallyModelled", "HasNeutralSummaryNoFlow", "(System.Object)", "summary", "manual"]
7+
- [ "Sinks", "NewSinks", "NoSink", "(System.Object)", "summary", "df-generated"]
8+
- [ "Sinks", "NewSinks", "NoSink", "(System.Object)", "sink", "manual"]

csharp/ql/test/utils/modelgenerator/dataflow/Sinks.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class NewSinks
2020
// neutral=Sinks;NewSinks;Sink2;(System.Object);summary;df-generated
2121
public static void Sink2(object o) => throw null;
2222

23+
// Defined as sink neutral in the file next to the neutral summary test.
24+
// neutral=Sinks;NewSinks;NoSink;(System.Object);summary;df-generated
25+
public static void NoSink(object o) => throw null;
26+
2327
// New sink
2428
// sink=Sinks;NewSinks;false;WrapResponseWrite;(System.Object);;Argument[0];html-injection;df-generated
2529
// neutral=Sinks;NewSinks;WrapResponseWrite;(System.Object);summary;df-generated

go/ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,3 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
597597
summaryElement(this, _, _, _, provenance, _)
598598
}
599599
}
600-
601-
// adapter class for converting Mad neutrals to `NeutralCallable`s
602-
private class NeutralCallableAdapter extends NeutralCallable {
603-
string kind;
604-
string provenance_;
605-
606-
NeutralCallableAdapter() { neutralElement(this, kind, provenance_) }
607-
608-
override string getKind() { result = kind }
609-
610-
override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
611-
}

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ private string positionToString(int pos) {
2323
module Input implements InputSig<Location, DataFlowImplSpecific::GoDataFlow> {
2424
class SummarizedCallableBase = Callable;
2525

26+
predicate neutralElement(
27+
Input::SummarizedCallableBase c, string kind, string provenance, boolean isExact
28+
) {
29+
exists(string namespace, string type, string name, string signature |
30+
neutralModel(namespace, type, name, signature, kind, provenance) and
31+
c.asFunction() = interpretElement(namespace, type, false, name, signature, "").asEntity()
32+
) and
33+
// isExact is not needed for Go.
34+
isExact = false
35+
}
36+
2637
ArgumentPosition callbackSelfParameterPosition() { result = -1 }
2738

2839
ReturnKind getStandardReturnValueKind() { result = getReturnKind(0) }
@@ -304,10 +315,7 @@ module Private {
304315
* and with provenance `provenance`.
305316
*/
306317
predicate neutralElement(Input::SummarizedCallableBase c, string kind, string provenance) {
307-
exists(string namespace, string type, string name, string signature |
308-
neutralModel(namespace, type, name, signature, kind, provenance) and
309-
c.asFunction() = interpretElement(namespace, type, false, name, signature, "").asEntity()
310-
)
318+
Input::neutralElement(c, kind, provenance, _)
311319
}
312320
}
313321

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -636,21 +636,6 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
636636
override predicate hasExactModel() { summaryElement(this, _, _, _, _, _, true) }
637637
}
638638

639-
// adapter class for converting Mad neutrals to `NeutralCallable`s
640-
private class NeutralCallableAdapter extends NeutralCallable {
641-
string kind;
642-
string provenance_;
643-
boolean exact;
644-
645-
NeutralCallableAdapter() { neutralElement(this, kind, provenance_, exact) }
646-
647-
override string getKind() { result = kind }
648-
649-
override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
650-
651-
override predicate hasExactModel() { exact = true }
652-
}
653-
654639
/**
655640
* A callable where there exists a MaD sink model that applies to it.
656641
*/

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ private string positionToString(int pos) {
2929
module Input implements InputSig<Location, DataFlowImplSpecific::JavaDataFlow> {
3030
class SummarizedCallableBase = FlowSummary::SummarizedCallableBase;
3131

32+
predicate neutralElement(
33+
Input::SummarizedCallableBase c, string kind, string provenance, boolean isExact
34+
) {
35+
exists(string namespace, string type, string name, string signature |
36+
neutralModel(namespace, type, name, signature, kind, provenance) and
37+
c.asCallable() = interpretElement(namespace, type, false, name, signature, "", isExact)
38+
)
39+
}
40+
3241
ArgumentPosition callbackSelfParameterPosition() { result = -1 }
3342

3443
ReturnKind getStandardReturnValueKind() { any() }
@@ -332,18 +341,7 @@ module Private {
332341
)
333342
}
334343

335-
/**
336-
* Holds if a neutral model exists for `c` of kind `kind`
337-
* and with provenance `provenance`.
338-
*/
339-
predicate neutralElement(
340-
Input::SummarizedCallableBase c, string kind, string provenance, boolean isExact
341-
) {
342-
exists(string namespace, string type, string name, string signature |
343-
neutralModel(namespace, type, name, signature, kind, provenance) and
344-
c.asCallable() = interpretElement(namespace, type, false, name, signature, "", isExact)
345-
)
346-
}
344+
predicate neutralElement = Input::neutralElement/4;
347345
}
348346

349347
/** Provides predicates for constructing summary components. */

0 commit comments

Comments
 (0)