Skip to content

Commit ce6fd8a

Browse files
authored
Merge pull request github#13432 from michaelnebel/updateissupported
Java/C#: Update telemetry queries to report callables with sink/source neutrals as being supported.
2 parents a9ea61f + 51f166d commit ce6fd8a

File tree

24 files changed

+30266
-30087
lines changed

24 files changed

+30266
-30087
lines changed

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

Lines changed: 25 additions & 4 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,11 @@ module Private {
13181333
/** Gets the string representation of this callable used by `neutral/1`. */
13191334
abstract string getCallableCsv();
13201335

1336+
/**
1337+
* Gets the kind of the neutral.
1338+
*/
1339+
string getKind() { result = super.getKind() }
1340+
13211341
string toString() { result = super.toString() }
13221342
}
13231343

@@ -1358,12 +1378,13 @@ module Private {
13581378

13591379
/**
13601380
* Holds if a neutral model `csv` exists (semi-colon separated format). Used for testing purposes.
1361-
* The syntax is: "namespace;type;name;signature;provenance"",
1381+
* The syntax is: "namespace;type;name;signature;kind;provenance"",
13621382
*/
13631383
query predicate neutral(string csv) {
13641384
exists(RelevantNeutralCallable c |
13651385
csv =
13661386
c.getCallableCsv() // Callable information
1387+
+ c.getKind() + ";" // kind
13671388
+ renderProvenanceNeutral(c) // provenance
13681389
)
13691390
}

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
}

csharp/ql/test/library-tests/dataflow/library/FlowSummaries.expected

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

csharp/ql/test/library-tests/dataflow/library/FlowSummaries.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private class IncludeAllSummarizedCallable extends IncludeSummarizedCallable {
66
IncludeAllSummarizedCallable() { exists(this) }
77
}
88

9-
private class IncludeNeutralCallable extends RelevantNeutralCallable instanceof FlowSummaryImpl::Public::NeutralCallable
9+
private class IncludeNeutralSummarizedCallable extends RelevantNeutralCallable instanceof FlowSummaryImpl::Public::NeutralSummaryCallable
1010
{
1111
/** Gets a string representing the callable in semi-colon separated format for use in flow summaries. */
1212
final override string getCallableCsv() { result = Csv::asPartialNeutralModel(this) }

csharp/ql/test/query-tests/Telemetry/SupportedExternalApis/SupportedExternalApis.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ public void M1()
1515
public void M2()
1616
{
1717
var d0 = new DateTime(); // Uninteresting parameterless constructor
18-
var next0 = d0.AddYears(30); // Has no flow summary, supported as negative summary
18+
var next0 = d0.AddYears(30); // Has no flow summary, supported as neutral summary model
1919

20-
var d1 = new DateTime(2000, 1, 1); // Interesting constructor, supported as negative summary
21-
var next1 = next0.AddDays(3); // Has no flow summary, supported as negative summary
22-
var next2 = next1.AddYears(5); // Has no flow summary, supported as negative summary
20+
var d1 = new DateTime(2000, 1, 1); // Interesting constructor, supported as neutral summary model
21+
var next1 = next0.AddDays(3); // Has no flow summary, supported as neutral summary model
22+
var next2 = next1.AddYears(5); // Has no flow summary, supported as neutral summary model
2323
}
2424

2525
public void M3()
2626
{
27-
var guid1 = Guid.Parse("{12345678-1234-1234-1234-123456789012}"); // Has no flow summary, supported as negative summary
27+
var guid1 = Guid.Parse("{12345678-1234-1234-1234-123456789012}"); // Has no flow summary, supported as neutral summary model
2828
}
2929

30-
public void M4()
30+
public void M4()
3131
{
3232
var o = new object(); // Uninteresting parameterless constructor
3333
var response = new HttpResponse(); // Uninteresting parameterless constructor
@@ -38,11 +38,11 @@ public void M4()
3838
response.Write(o); // Known sink
3939
}
4040

41-
public void M5()
41+
public void M5()
4242
{
4343
var l1 = Console.ReadLine(); // Known source
4444
var l2 = Console.ReadLine(); // Known source
45-
Console.SetError(Console.Out); // Has no flow summary, supported as negative summary
45+
Console.SetError(Console.Out); // Has no flow summary, supported as neutral summary model
4646
var x = Console.Read(); // Known source
4747
}
4848
}

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

Lines changed: 25 additions & 4 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,11 @@ module Private {
13181333
/** Gets the string representation of this callable used by `neutral/1`. */
13191334
abstract string getCallableCsv();
13201335

1336+
/**
1337+
* Gets the kind of the neutral.
1338+
*/
1339+
string getKind() { result = super.getKind() }
1340+
13211341
string toString() { result = super.toString() }
13221342
}
13231343

@@ -1358,12 +1378,13 @@ module Private {
13581378

13591379
/**
13601380
* Holds if a neutral model `csv` exists (semi-colon separated format). Used for testing purposes.
1361-
* The syntax is: "namespace;type;name;signature;provenance"",
1381+
* The syntax is: "namespace;type;name;signature;kind;provenance"",
13621382
*/
13631383
query predicate neutral(string csv) {
13641384
exists(RelevantNeutralCallable c |
13651385
csv =
13661386
c.getCallableCsv() // Callable information
1387+
+ c.getKind() + ";" // kind
13671388
+ renderProvenanceNeutral(c) // provenance
13681389
)
13691390
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ private module FlowSummaries {
1515
private import semmle.go.dataflow.FlowSummary as F
1616
}
1717

18+
/**
19+
* A class of callables that are candidates for flow summary modeling.
20+
*/
1821
class SummarizedCallableBase = Callable;
1922

23+
/**
24+
* A class of callables that are candidates for neutral modeling.
25+
*/
26+
class NeutralCallableBase = Callable;
27+
2028
DataFlowCallable inject(SummarizedCallable c) { result.asSummarizedCallable() = c or none() }
2129

2230
/** Gets the parameter position of the instance parameter. */
@@ -73,11 +81,11 @@ predicate summaryElement(
7381
}
7482

7583
/**
76-
* Holds if a neutral summary model exists for `c` with provenance `provenance`,
77-
* which means that there is no flow through `c`.
84+
* Holds if a neutral model exists for `c` of kind `kind`
85+
* and with provenance `provenance`.
7886
* Note. Neutral models have not been implemented for Go.
7987
*/
80-
predicate neutralSummaryElement(SummarizedCallable c, string provenance) { none() }
88+
predicate neutralElement(NeutralCallableBase c, string kind, string provenance) { none() }
8189

8290
/** Gets the summary component for specification component `c`, if any. */
8391
bindingset[c]

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ class Provenance = Impl::Public::Provenance;
175175

176176
class SummarizedCallable = Impl::Public::SummarizedCallable;
177177

178-
class NeutralCallable = Impl::Public::NeutralCallable;
179-
180178
/**
181179
* An adapter class to add the flow summaries specified on `SyntheticCallable`
182180
* to `SummarizedCallable`.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ private import java
22
private import DataFlowPrivate
33
private import DataFlowUtil
44
private import semmle.code.java.dataflow.InstanceAccess
5-
private import semmle.code.java.dataflow.FlowSummary
5+
private import semmle.code.java.dataflow.internal.FlowSummaryImpl as Impl
66
private import semmle.code.java.dispatch.VirtualDispatch as VirtualDispatch
77
private import semmle.code.java.dataflow.TypeFlow
88
private import semmle.code.java.dispatch.internal.Unification
99

1010
private module DispatchImpl {
1111
private predicate hasHighConfidenceTarget(Call c) {
12-
exists(SummarizedCallable sc | sc.getACall() = c and not sc.applyGeneratedModel())
12+
exists(Impl::Public::SummarizedCallable sc | sc.getACall() = c and not sc.applyGeneratedModel())
1313
or
14-
exists(NeutralCallable nc | nc.getACall() = c and nc.hasManualModel())
14+
exists(Impl::Public::NeutralSummaryCallable nc | nc.getACall() = c and nc.hasManualModel())
1515
or
1616
exists(Callable srcTgt |
1717
srcTgt = VirtualDispatch::viableCallable(c) and

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

Lines changed: 25 additions & 4 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,11 @@ module Private {
13181333
/** Gets the string representation of this callable used by `neutral/1`. */
13191334
abstract string getCallableCsv();
13201335

1336+
/**
1337+
* Gets the kind of the neutral.
1338+
*/
1339+
string getKind() { result = super.getKind() }
1340+
13211341
string toString() { result = super.toString() }
13221342
}
13231343

@@ -1358,12 +1378,13 @@ module Private {
13581378

13591379
/**
13601380
* Holds if a neutral model `csv` exists (semi-colon separated format). Used for testing purposes.
1361-
* The syntax is: "namespace;type;name;signature;provenance"",
1381+
* The syntax is: "namespace;type;name;signature;kind;provenance"",
13621382
*/
13631383
query predicate neutral(string csv) {
13641384
exists(RelevantNeutralCallable c |
13651385
csv =
13661386
c.getCallableCsv() // Callable information
1387+
+ c.getKind() + ";" // kind
13671388
+ renderProvenanceNeutral(c) // provenance
13681389
)
13691390
}

0 commit comments

Comments
 (0)