Skip to content

Commit 3fa990a

Browse files
michaelnebelhvitved
authored andcommitted
C#: Make sure that all callables with a summary are added to the external SummarizedCallable class.
1 parent 4810419 commit 3fa990a

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ Element interpretElement(
516516
* Holds if `c` has a `generated` summary.
517517
*/
518518
predicate hasSummary(Callable c, boolean generated) {
519-
exists(DataFlowCallable dc | dc.asCallable() = c and summaryElement(dc, _, _, _, generated))
519+
exists(DataFlowCallable dc |
520+
dc.asSummarizedCallable() = c and summaryElement(dc, _, _, _, generated)
521+
)
520522
}
521523

522524
cached

csharp/ql/lib/semmle/code/csharp/dataflow/FlowSummary.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ module SummaryComponentStack {
118118
* A class for synthesized callables given by a summary.
119119
*/
120120
abstract class SummarizedCallable extends DotNet::Callable {
121+
SummarizedCallable() { this.isUnboundDeclaration() }
122+
121123
/**
122124
* Holds if data may flow from `input` to `output` through this callable.
123125
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private predicate summarizedCallable(DataFlowCallable c) {
2929
*/
3030
DotNet::Callable getCallableForDataFlow(DotNet::Callable c) {
3131
exists(DotNet::Callable unboundDecl | unboundDecl = c.getUnboundDeclaration() |
32-
summarizedCallable(TDotNetCallable(unboundDecl)) and
32+
summarizedCallable(TSummarizedCallable(unboundDecl)) and
3333
result = unboundDecl
3434
or
3535
result.hasBody() and

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private import FlowSummaryImpl::Private
1313
private import FlowSummaryImpl::Public
1414
private import semmle.code.csharp.Unification
1515
private import semmle.code.csharp.dataflow.ExternalFlow
16+
private import semmle.code.csharp.dataflow.FlowSummary as FlowSummary
1617

1718
/** Gets the parameter position of the instance parameter. */
1819
ArgumentPosition instanceParameterPosition() { none() } // disables implicit summary flow to `this` for callbacks
@@ -84,6 +85,21 @@ DataFlowType getCallbackReturnType(DataFlowType t, ReturnKind rk) {
8485
)
8586
}
8687

88+
private predicate summaryElement0(
89+
DotNet::Callable c, string input, string output, string kind, boolean generated
90+
) {
91+
exists(
92+
string namespace, string type, boolean subtypes, string name, string signature, string ext
93+
|
94+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated) and
95+
c = interpretElement(namespace, type, subtypes, name, signature, ext)
96+
)
97+
}
98+
99+
private class SummarizedCallableExternal extends FlowSummary::SummarizedCallable {
100+
SummarizedCallableExternal() { summaryElement0(this, _, _, _, _) }
101+
}
102+
87103
/**
88104
* Holds if an external flow summary exists for `c` with input specification
89105
* `input`, output specification `output`, kind `kind`, and a flag `generated`
@@ -92,12 +108,7 @@ DataFlowType getCallbackReturnType(DataFlowType t, ReturnKind rk) {
92108
predicate summaryElement(
93109
DataFlowCallable c, string input, string output, string kind, boolean generated
94110
) {
95-
exists(
96-
string namespace, string type, boolean subtypes, string name, string signature, string ext
97-
|
98-
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated) and
99-
c.asCallable() = interpretElement(namespace, type, subtypes, name, signature, ext)
100-
)
111+
summaryElement0(c.asSummarizedCallable(), input, output, kind, generated)
101112
}
102113

103114
/**

0 commit comments

Comments
 (0)