Skip to content

Commit 35c654a

Browse files
committed
Go: Use FlowSummaryImpl from dataflow pack
1 parent faaa558 commit 35c654a

File tree

9 files changed

+303
-1904
lines changed

9 files changed

+303
-1904
lines changed

config/identical-files.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
],
5656
"DataFlow Java/C#/Go/Ruby/Python/Swift Flow Summaries": [
5757
"java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll",
58-
"go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll",
5958
"swift/ql/lib/codeql/swift/dataflow/internal/FlowSummaryImpl.qll"
6059
],
6160
"SsaReadPosition Java/C#": [
@@ -464,7 +463,6 @@
464463
"ruby/ql/lib/codeql/ruby/typetracking/internal/SummaryTypeTracker.qll"
465464
],
466465
"AccessPathSyntax": [
467-
"go/ql/lib/semmle/go/dataflow/internal/AccessPathSyntax.qll",
468466
"java/ql/lib/semmle/code/java/dataflow/internal/AccessPathSyntax.qll",
469467
"swift/ql/lib/codeql/swift/dataflow/internal/AccessPathSyntax.qll"
470468
],

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

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@
7676
private import go
7777
import internal.ExternalFlowExtensions
7878
private import internal.DataFlowPrivate
79+
private import internal.FlowSummaryImpl
80+
private import internal.FlowSummaryImpl::Private
7981
private import internal.FlowSummaryImpl::Private::External
80-
private import internal.FlowSummaryImplSpecific
81-
private import internal.AccessPathSyntax
82-
private import FlowSummary
82+
private import internal.FlowSummaryImpl::Public
8383
private import codeql.mad.ModelValidation as SharedModelVal
8484

8585
/** Holds if `package` have MaD framework coverage. */
@@ -274,7 +274,7 @@ private string interpretPackage(string p) {
274274
}
275275

276276
/** Gets the source/sink/summary element corresponding to the supplied parameters. */
277-
SourceOrSinkElement interpretElement(
277+
SourceSinkInterpretationInput::SourceOrSinkElement interpretElement(
278278
string pkg, string type, boolean subtypes, string name, string signature, string ext
279279
) {
280280
elementSpec(pkg, type, subtypes, name, signature, ext) and
@@ -298,8 +298,9 @@ SourceOrSinkElement interpretElement(
298298
predicate hasExternalSpecification(Function f) {
299299
f = any(SummarizedCallable sc).asFunction()
300300
or
301-
exists(SourceOrSinkElement e | f = e.asEntity() |
302-
sourceElement(e, _, _, _) or sinkElement(e, _, _, _)
301+
exists(SourceSinkInterpretationInput::SourceOrSinkElement e | f = e.asEntity() |
302+
SourceSinkInterpretationInput::sourceElement(e, _, _) or
303+
SourceSinkInterpretationInput::sinkElement(e, _, _)
303304
)
304305
}
305306

@@ -353,7 +354,9 @@ private module Cached {
353354
*/
354355
cached
355356
predicate sourceNode(DataFlow::Node node, string kind) {
356-
exists(InterpretNode n | isSourceNode(n, kind) and n.asNode() = node)
357+
exists(SourceSinkInterpretationInput::InterpretNode n |
358+
isSourceNode(n, kind) and n.asNode() = node
359+
)
357360
}
358361

359362
/**
@@ -362,8 +365,71 @@ private module Cached {
362365
*/
363366
cached
364367
predicate sinkNode(DataFlow::Node node, string kind) {
365-
exists(InterpretNode n | isSinkNode(n, kind) and n.asNode() = node)
368+
exists(SourceSinkInterpretationInput::InterpretNode n |
369+
isSinkNode(n, kind) and n.asNode() = node
370+
)
366371
}
367372
}
368373

369374
import Cached
375+
376+
private predicate interpretSummary(
377+
Callable c, string input, string output, string kind, string provenance
378+
) {
379+
exists(
380+
string namespace, string type, boolean subtypes, string name, string signature, string ext
381+
|
382+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance) and
383+
c.asFunction() = interpretElement(namespace, type, subtypes, name, signature, ext).asEntity()
384+
)
385+
}
386+
387+
private class SummarizedCallableAdapter extends SummarizedCallable {
388+
SummarizedCallableAdapter() { interpretSummary(this, _, _, _, _) }
389+
390+
private predicate relevantSummaryElementManual(string input, string output, string kind) {
391+
exists(Provenance provenance |
392+
interpretSummary(this, input, output, kind, provenance) and
393+
provenance.isManual()
394+
)
395+
}
396+
397+
private predicate relevantSummaryElementGenerated(string input, string output, string kind) {
398+
exists(Provenance provenance |
399+
interpretSummary(this, input, output, kind, provenance) and
400+
provenance.isGenerated()
401+
)
402+
}
403+
404+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
405+
exists(string kind |
406+
this.relevantSummaryElementManual(input, output, kind)
407+
or
408+
not this.relevantSummaryElementManual(_, _, _) and
409+
this.relevantSummaryElementGenerated(input, output, kind)
410+
|
411+
if kind = "value" then preservesValue = true else preservesValue = false
412+
)
413+
}
414+
415+
override predicate hasProvenance(Provenance provenance) {
416+
interpretSummary(this, _, _, _, provenance)
417+
}
418+
}
419+
420+
private class NeutralCallableAdapter extends NeutralCallable {
421+
string kind;
422+
string provenance_;
423+
424+
NeutralCallableAdapter() {
425+
// Neutral models have not been implemented for Go.
426+
none() and
427+
exists(this) and
428+
exists(kind) and
429+
exists(provenance_)
430+
}
431+
432+
override string getKind() { result = kind }
433+
434+
override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
435+
}

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

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,14 @@ private import internal.DataFlowUtil
1010
// import all instances below
1111
private module Summaries { }
1212

13-
class SummaryComponent = Impl::Public::SummaryComponent;
13+
deprecated class SummaryComponent = Impl::Private::SummaryComponent;
1414

15-
/** Provides predicates for constructing summary components. */
16-
module SummaryComponent {
17-
import Impl::Public::SummaryComponent
15+
deprecated module SummaryComponent = Impl::Private::SummaryComponent;
1816

19-
/** Gets a summary component that represents a qualifier. */
20-
SummaryComponent qualifier() { result = argument(-1) }
17+
deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack;
2118

22-
/** Gets a summary component for field `f`. */
23-
SummaryComponent field(Field f) { result = content(any(FieldContent c | c.getField() = f)) }
24-
25-
/** Gets a summary component that represents the return value of a call. */
26-
SummaryComponent return() { result = return(_) }
27-
}
28-
29-
class SummaryComponentStack = Impl::Public::SummaryComponentStack;
30-
31-
/** Provides predicates for constructing stacks of summary components. */
32-
module SummaryComponentStack {
33-
import Impl::Public::SummaryComponentStack
34-
35-
/** Gets a singleton stack representing a qualifier. */
36-
SummaryComponentStack qualifier() { result = singleton(SummaryComponent::qualifier()) }
37-
38-
/** Gets a stack representing a field `f` of `object`. */
39-
SummaryComponentStack fieldOf(Field f, SummaryComponentStack object) {
40-
result = push(SummaryComponent::field(f), object)
41-
}
42-
43-
/** Gets a singleton stack representing a (normal) return. */
44-
SummaryComponentStack return() { result = singleton(SummaryComponent::return()) }
45-
}
19+
deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
4620

4721
class SummarizedCallable = Impl::Public::SummarizedCallable;
4822

49-
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
23+
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;

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

Lines changed: 0 additions & 182 deletions
This file was deleted.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ module Private {
8686

8787
/** Holds if this summary node is the `i`th argument of `call`. */
8888
predicate isArgumentOf(DataFlowCall call, int i) {
89-
FlowSummaryImpl::Private::summaryArgumentNode(call, this.getSummaryNode(), i)
89+
// We do not currently have support for callback-based library models.
90+
none()
9091
}
9192

9293
/** Holds if this summary node is a return node. */
@@ -96,7 +97,8 @@ module Private {
9697

9798
/** Holds if this summary node is an out node for `call`. */
9899
predicate isOut(DataFlowCall call) {
99-
FlowSummaryImpl::Private::summaryOutNode(call, this.getSummaryNode(), _)
100+
// We do not currently have support for callback-based library models.
101+
none()
100102
}
101103
}
102104
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preserves
420420
* by default as a heuristic.
421421
*/
422422
predicate allowParameterReturnInSelf(ParameterNode p) {
423-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(p)
423+
exists(DataFlowCallable c, int pos |
424+
p.isParameterOf(c, pos) and
425+
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asSummarizedCallable(), pos)
426+
)
424427
}
425428

426429
/** An approximated `Content`. */

0 commit comments

Comments
 (0)