Skip to content

Commit 2d3f96f

Browse files
committed
Swift: Use FlowSummaryImpl from dataflow pack
1 parent 35c654a commit 2d3f96f

File tree

8 files changed

+268
-1898
lines changed

8 files changed

+268
-1898
lines changed

config/identical-files.json

-8
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
"ruby/ql/lib/codeql/ruby/dataflow/internal/tainttracking1/TaintTrackingImpl.qll",
5454
"swift/ql/lib/codeql/swift/dataflow/internal/tainttracking1/TaintTrackingImpl.qll"
5555
],
56-
"DataFlow Java/C#/Go/Ruby/Python/Swift Flow Summaries": [
57-
"java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll",
58-
"swift/ql/lib/codeql/swift/dataflow/internal/FlowSummaryImpl.qll"
59-
],
6056
"SsaReadPosition Java/C#": [
6157
"java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll",
6258
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll"
@@ -462,10 +458,6 @@
462458
"python/ql/lib/semmle/python/dataflow/new/internal/SummaryTypeTracker.qll",
463459
"ruby/ql/lib/codeql/ruby/typetracking/internal/SummaryTypeTracker.qll"
464460
],
465-
"AccessPathSyntax": [
466-
"java/ql/lib/semmle/code/java/dataflow/internal/AccessPathSyntax.qll",
467-
"swift/ql/lib/codeql/swift/dataflow/internal/AccessPathSyntax.qll"
468-
],
469461
"IncompleteUrlSubstringSanitization": [
470462
"javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitization.qll",
471463
"ruby/ql/src/queries/security/cwe-020/IncompleteUrlSubstringSanitization.qll"

swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll

+73-8
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@
6666
*/
6767

6868
import swift
69-
private import internal.AccessPathSyntax
7069
private import internal.DataFlowDispatch
7170
private import internal.DataFlowPrivate
7271
private import internal.DataFlowPublic
72+
private import internal.FlowSummaryImpl
7373
private import internal.FlowSummaryImpl::Public
74+
private import internal.FlowSummaryImpl::Private
7475
private import internal.FlowSummaryImpl::Private::External
75-
private import internal.FlowSummaryImplSpecific
7676
private import FlowSummary as FlowSummary
7777
private import codeql.mad.ModelValidation as SharedModelVal
7878

@@ -451,7 +451,7 @@ Element interpretElement(
451451
)
452452
}
453453

454-
private predicate parseField(AccessPathToken c, Content::FieldContent f) {
454+
deprecated private predicate parseField(AccessPathToken c, Content::FieldContent f) {
455455
exists(string fieldRegex, string name |
456456
c.getName() = "Field" and
457457
fieldRegex = "^([^.]+)$" and
@@ -460,12 +460,12 @@ private predicate parseField(AccessPathToken c, Content::FieldContent f) {
460460
)
461461
}
462462

463-
private predicate parseTuple(AccessPathToken c, Content::TupleContent t) {
463+
deprecated private predicate parseTuple(AccessPathToken c, Content::TupleContent t) {
464464
c.getName() = "TupleElement" and
465465
t.getIndex() = c.getAnArgument().toInt()
466466
}
467467

468-
private predicate parseEnum(AccessPathToken c, Content::EnumContent e) {
468+
deprecated private predicate parseEnum(AccessPathToken c, Content::EnumContent e) {
469469
c.getName() = "EnumElement" and
470470
c.getAnArgument() = e.getSignature()
471471
or
@@ -474,7 +474,7 @@ private predicate parseEnum(AccessPathToken c, Content::EnumContent e) {
474474
}
475475

476476
/** Holds if the specification component parses as a `Content`. */
477-
predicate parseContent(AccessPathToken component, Content content) {
477+
deprecated predicate parseContent(AccessPathToken component, Content content) {
478478
parseField(component, content)
479479
or
480480
parseTuple(component, content)
@@ -497,7 +497,9 @@ private module Cached {
497497
*/
498498
cached
499499
predicate sourceNode(Node node, string kind) {
500-
exists(InterpretNode n | isSourceNode(n, kind) and n.asNode() = node)
500+
exists(SourceSinkInterpretationInput::InterpretNode n |
501+
isSourceNode(n, kind) and n.asNode() = node
502+
)
501503
}
502504

503505
/**
@@ -506,8 +508,71 @@ private module Cached {
506508
*/
507509
cached
508510
predicate sinkNode(Node node, string kind) {
509-
exists(InterpretNode n | isSinkNode(n, kind) and n.asNode() = node)
511+
exists(SourceSinkInterpretationInput::InterpretNode n |
512+
isSinkNode(n, kind) and n.asNode() = node
513+
)
510514
}
511515
}
512516

513517
import Cached
518+
519+
private predicate interpretSummary(
520+
Function f, string input, string output, string kind, string provenance
521+
) {
522+
exists(
523+
string namespace, string type, boolean subtypes, string name, string signature, string ext
524+
|
525+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance) and
526+
f = interpretElement(namespace, type, subtypes, name, signature, ext)
527+
)
528+
}
529+
530+
private class SummarizedCallableAdapter extends SummarizedCallable {
531+
SummarizedCallableAdapter() { interpretSummary(this, _, _, _, _) }
532+
533+
private predicate relevantSummaryElementManual(string input, string output, string kind) {
534+
exists(Provenance provenance |
535+
interpretSummary(this, input, output, kind, provenance) and
536+
provenance.isManual()
537+
)
538+
}
539+
540+
private predicate relevantSummaryElementGenerated(string input, string output, string kind) {
541+
exists(Provenance provenance |
542+
interpretSummary(this, input, output, kind, provenance) and
543+
provenance.isGenerated()
544+
)
545+
}
546+
547+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
548+
exists(string kind |
549+
this.relevantSummaryElementManual(input, output, kind)
550+
or
551+
not this.relevantSummaryElementManual(_, _, _) and
552+
this.relevantSummaryElementGenerated(input, output, kind)
553+
|
554+
if kind = "value" then preservesValue = true else preservesValue = false
555+
)
556+
}
557+
558+
override predicate hasProvenance(Provenance provenance) {
559+
interpretSummary(this, _, _, _, provenance)
560+
}
561+
}
562+
563+
private class NeutralCallableAdapter extends NeutralCallable {
564+
string kind;
565+
string provenance_;
566+
567+
NeutralCallableAdapter() {
568+
// Neutral models have not been implemented for Swift.
569+
none() and
570+
exists(this) and
571+
exists(kind) and
572+
exists(provenance_)
573+
}
574+
575+
override string getKind() { result = kind }
576+
577+
override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
578+
}

swift/ql/lib/codeql/swift/dataflow/FlowSummary.qll

+5-27
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,14 @@ private module Summaries {
1313
private import codeql.swift.frameworks.Frameworks
1414
}
1515

16-
class SummaryComponent = Impl::Public::SummaryComponent;
16+
deprecated class SummaryComponent = Impl::Private::SummaryComponent;
1717

18-
/** Provides predicates for constructing summary components. */
19-
module SummaryComponent {
20-
private import Impl::Public::SummaryComponent as SummaryComponentInternal
18+
deprecated module SummaryComponent = Impl::Private::SummaryComponent;
2119

22-
predicate content = SummaryComponentInternal::content/1;
20+
deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack;
2321

24-
predicate parameter = SummaryComponentInternal::parameter/1;
25-
26-
predicate argument = SummaryComponentInternal::argument/1;
27-
28-
predicate return = SummaryComponentInternal::return/1;
29-
}
30-
31-
class SummaryComponentStack = Impl::Public::SummaryComponentStack;
32-
33-
/** Provides predicates for constructing stacks of summary components. */
34-
module SummaryComponentStack {
35-
private import Impl::Public::SummaryComponentStack as SummaryComponentStackInternal
36-
37-
predicate singleton = SummaryComponentStackInternal::singleton/1;
38-
39-
predicate push = SummaryComponentStackInternal::push/2;
40-
41-
predicate argument = SummaryComponentStackInternal::argument/1;
42-
43-
predicate return = SummaryComponentStackInternal::return/1;
44-
}
22+
deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
4523

4624
class SummarizedCallable = Impl::Public::SummarizedCallable;
4725

48-
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
26+
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;

swift/ql/lib/codeql/swift/dataflow/internal/AccessPathSyntax.qll

-182
This file was deleted.

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowDispatch.qll

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ private import codeql.swift.controlflow.ControlFlowGraph
55
private import codeql.swift.controlflow.CfgNodes
66
private import codeql.swift.controlflow.internal.Scope
77
private import FlowSummaryImpl as FlowSummaryImpl
8-
private import FlowSummaryImplSpecific as FlowSummaryImplSpecific
98
private import codeql.swift.dataflow.FlowSummary as FlowSummary
109

1110
newtype TReturnKind =

0 commit comments

Comments
 (0)