Skip to content

Commit

Permalink
Swift: Use FlowSummaryImpl from dataflow pack
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Nov 27, 2023
1 parent 638b56c commit 5f79e7c
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 1,891 deletions.
81 changes: 73 additions & 8 deletions swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
*/

import swift
private import internal.AccessPathSyntax
private import internal.DataFlowDispatch
private import internal.DataFlowPrivate
private import internal.DataFlowPublic
private import internal.FlowSummaryImpl
private import internal.FlowSummaryImpl::Public
private import internal.FlowSummaryImpl::Private
private import internal.FlowSummaryImpl::Private::External
private import internal.FlowSummaryImplSpecific
private import FlowSummary as FlowSummary
private import codeql.mad.ModelValidation as SharedModelVal

Expand Down Expand Up @@ -451,7 +451,7 @@ Element interpretElement(
)
}

private predicate parseField(AccessPathToken c, Content::FieldContent f) {
deprecated private predicate parseField(AccessPathToken c, Content::FieldContent f) {
exists(string fieldRegex, string name |
c.getName() = "Field" and
fieldRegex = "^([^.]+)$" and
Expand All @@ -460,12 +460,12 @@ private predicate parseField(AccessPathToken c, Content::FieldContent f) {
)
}

private predicate parseTuple(AccessPathToken c, Content::TupleContent t) {
deprecated private predicate parseTuple(AccessPathToken c, Content::TupleContent t) {
c.getName() = "TupleElement" and
t.getIndex() = c.getAnArgument().toInt()
}

private predicate parseEnum(AccessPathToken c, Content::EnumContent e) {
deprecated private predicate parseEnum(AccessPathToken c, Content::EnumContent e) {
c.getName() = "EnumElement" and
c.getAnArgument() = e.getSignature()
or
Expand All @@ -474,7 +474,7 @@ private predicate parseEnum(AccessPathToken c, Content::EnumContent e) {
}

/** Holds if the specification component parses as a `Content`. */
predicate parseContent(AccessPathToken component, Content content) {
deprecated predicate parseContent(AccessPathToken component, Content content) {
parseField(component, content)
or
parseTuple(component, content)
Expand All @@ -497,7 +497,9 @@ private module Cached {
*/
cached
predicate sourceNode(Node node, string kind) {
exists(InterpretNode n | isSourceNode(n, kind) and n.asNode() = node)
exists(SourceSinkInterpretationInput::InterpretNode n |
isSourceNode(n, kind) and n.asNode() = node
)
}

/**
Expand All @@ -506,8 +508,71 @@ private module Cached {
*/
cached
predicate sinkNode(Node node, string kind) {
exists(InterpretNode n | isSinkNode(n, kind) and n.asNode() = node)
exists(SourceSinkInterpretationInput::InterpretNode n |
isSinkNode(n, kind) and n.asNode() = node
)
}
}

import Cached

private predicate interpretSummary(
Function f, string input, string output, string kind, string provenance
) {
exists(
string namespace, string type, boolean subtypes, string name, string signature, string ext
|
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance) and
f = interpretElement(namespace, type, subtypes, name, signature, ext)
)
}

private predicate relevantSummaryElementManual(
Function f, string input, string output, string kind, Provenance provenance
) {
interpretSummary(f, input, output, kind, provenance) and
provenance.isManual()
}

private predicate relevantSummaryElementGenerated(
Function f, string input, string output, string kind, Provenance provenance
) {
interpretSummary(f, input, output, kind, provenance) and
provenance.isGenerated()
}

private class SummarizedCallableAdapter extends SummarizedCallable {
string input_;
string output_;
string kind;
string provenance_;

SummarizedCallableAdapter() {
relevantSummaryElementManual(this, input_, output_, kind, provenance_)
or
relevantSummaryElementGenerated(this, input_, output_, kind, provenance_) and
not relevantSummaryElementManual(this, _, _, _, _)
}

override predicate propagatesFlow(string input, string output, boolean preservesValue) {
input = input_ and
output = output_ and
if kind = "value" then preservesValue = true else preservesValue = false
}

override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
}

private class NeutralCallableAdapter extends NeutralCallable {

Check warning

Code scanning / CodeQL

UnusedField Warning

This class declares the
field kind
but does not bind it in the characteristic predicate.
This class declares the
field provenance_
but does not bind it in the characteristic predicate.
string kind;
string provenance_;

NeutralCallableAdapter() {
// Neutral models have not been implemented for Swift.
none()
}

override string getKind() { result = kind }

override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
}
32 changes: 5 additions & 27 deletions swift/ql/lib/codeql/swift/dataflow/FlowSummary.qll
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,14 @@ private module Summaries {
private import codeql.swift.frameworks.Frameworks
}

class SummaryComponent = Impl::Public::SummaryComponent;
deprecated class SummaryComponent = Impl::Private::SummaryComponent;

/** Provides predicates for constructing summary components. */
module SummaryComponent {
private import Impl::Public::SummaryComponent as SummaryComponentInternal
deprecated module SummaryComponent = Impl::Private::SummaryComponent;

predicate content = SummaryComponentInternal::content/1;
deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack;

predicate parameter = SummaryComponentInternal::parameter/1;

predicate argument = SummaryComponentInternal::argument/1;

predicate return = SummaryComponentInternal::return/1;
}

class SummaryComponentStack = Impl::Public::SummaryComponentStack;

/** Provides predicates for constructing stacks of summary components. */
module SummaryComponentStack {
private import Impl::Public::SummaryComponentStack as SummaryComponentStackInternal

predicate singleton = SummaryComponentStackInternal::singleton/1;

predicate push = SummaryComponentStackInternal::push/2;

predicate argument = SummaryComponentStackInternal::argument/1;

predicate return = SummaryComponentStackInternal::return/1;
}
deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;

class SummarizedCallable = Impl::Public::SummarizedCallable;

class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;
182 changes: 0 additions & 182 deletions swift/ql/lib/codeql/swift/dataflow/internal/AccessPathSyntax.qll

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ private import codeql.swift.controlflow.ControlFlowGraph
private import codeql.swift.controlflow.CfgNodes
private import codeql.swift.controlflow.internal.Scope
private import FlowSummaryImpl as FlowSummaryImpl
private import FlowSummaryImplSpecific as FlowSummaryImplSpecific
private import codeql.swift.dataflow.FlowSummary as FlowSummary

newtype TReturnKind =
Expand Down
Loading

0 comments on commit 5f79e7c

Please sign in to comment.