Skip to content

Commit 6840a6d

Browse files
committed
C#: Re-factor NeutralCallable to include all neutrals and introduce NeutralSummaryCallable. Also include printing of the neutral kind in FlowSummaries testcase.
1 parent 8b5b153 commit 6840a6d

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,21 @@ module Public {
296296
predicate hasProvenance(Provenance provenance) { provenance = "manual" }
297297
}
298298

299-
/** A callable where there is no flow via the callable. */
300-
class NeutralCallable extends SummarizedCallableBase {
299+
/**
300+
* A callable where there is no flow via the callable.
301+
*/
302+
class NeutralSummaryCallable extends NeutralCallable {
303+
NeutralSummaryCallable() { this.getKind() = "summary" }
304+
}
305+
306+
/**
307+
* A callable that has a neutral model.
308+
*/
309+
class NeutralCallable extends NeutralCallableBase {
310+
private string kind;
301311
private Provenance provenance;
302312

303-
NeutralCallable() { neutralSummaryElement(this, provenance) }
313+
NeutralCallable() { neutralElement(this, kind, provenance) }
304314

305315
/**
306316
* Holds if the neutral is auto generated.
@@ -316,6 +326,11 @@ module Public {
316326
* Holds if the neutral has provenance `p`.
317327
*/
318328
predicate hasProvenance(Provenance p) { p = provenance }
329+
330+
/**
331+
* Gets the kind of the neutral.
332+
*/
333+
string getKind() { result = kind }
319334
}
320335
}
321336

@@ -1318,6 +1333,8 @@ module Private {
13181333
/** Gets the string representation of this callable used by `neutral/1`. */
13191334
abstract string getCallableCsv();
13201335

1336+
string getKind() { result = super.getKind() }
1337+
13211338
string toString() { result = super.toString() }
13221339
}
13231340

@@ -1364,6 +1381,7 @@ module Private {
13641381
exists(RelevantNeutralCallable c |
13651382
csv =
13661383
c.getCallableCsv() // Callable information
1384+
+ c.getKind() + ";" // kind
13671385
+ renderProvenanceNeutral(c) // provenance
13681386
)
13691387
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ private import semmle.code.csharp.Unification
1515
private import semmle.code.csharp.dataflow.ExternalFlow
1616
private import semmle.code.csharp.dataflow.FlowSummary as FlowSummary
1717

18-
class SummarizedCallableBase extends Callable {
19-
SummarizedCallableBase() { this.isUnboundDeclaration() }
20-
}
18+
/**
19+
* A class of callables that are candidates for flow summary modeling.
20+
*/
21+
class SummarizedCallableBase = UnboundCallable;
22+
23+
/**
24+
* A class of callables that are candidates for neutral modeling.
25+
*/
26+
class NeutralCallableBase = UnboundCallable;
2127

2228
/**
2329
* A module for importing frameworks that define synthetic globals.
@@ -120,12 +126,12 @@ predicate summaryElement(Callable c, string input, string output, string kind, s
120126
}
121127

122128
/**
123-
* Holds if a neutral summary model exists for `c` with provenance `provenace`,
124-
* which means that there is no flow through `c`.
129+
* Holds if a neutral model exists for `c` of kind `kind`
130+
* and with provenance `provenance`.
125131
*/
126-
predicate neutralSummaryElement(Callable c, string provenance) {
132+
predicate neutralElement(Callable c, string kind, string provenance) {
127133
exists(string namespace, string type, string name, string signature |
128-
neutralModel(namespace, type, name, signature, "summary", provenance) and
134+
neutralModel(namespace, type, name, signature, kind, provenance) and
129135
c = interpretElement(namespace, type, false, name, signature, "")
130136
)
131137
}

0 commit comments

Comments
 (0)