Skip to content

Commit 8cc509e

Browse files
authored
Merge pull request github#9275 from MathiasVP/swift-add-dataflow-lib
Swift: Add shared dataflow library
2 parents 54ac367 + 9b67912 commit 8cc509e

15 files changed

+8375
-5
lines changed

config/identical-files.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@
2929
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl4.qll",
3030
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImpl.qll",
3131
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImpl2.qll",
32-
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplForLibraries.qll"
32+
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplForLibraries.qll",
33+
"swift/ql/lib/codeql/swift/dataflow/internal/DataFlowImpl.qll"
3334
],
3435
"DataFlow Java/C++/C#/Python Common": [
3536
"java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll",
3637
"cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll",
3738
"cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplCommon.qll",
3839
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplCommon.qll",
3940
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImplCommon.qll",
40-
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplCommon.qll"
41+
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplCommon.qll",
42+
"swift/ql/lib/codeql/swift/dataflow/internal/DataFlowImplCommon.qll"
4143
],
4244
"TaintTracking::Configuration Java/C++/C#/Python": [
4345
"cpp/ql/lib/semmle/code/cpp/dataflow/internal/tainttracking1/TaintTrackingImpl.qll",
@@ -58,15 +60,17 @@
5860
"python/ql/lib/semmle/python/dataflow/new/internal/tainttracking3/TaintTrackingImpl.qll",
5961
"python/ql/lib/semmle/python/dataflow/new/internal/tainttracking4/TaintTrackingImpl.qll",
6062
"ruby/ql/lib/codeql/ruby/dataflow/internal/tainttracking1/TaintTrackingImpl.qll",
61-
"ruby/ql/lib/codeql/ruby/dataflow/internal/tainttrackingforlibraries/TaintTrackingImpl.qll"
63+
"ruby/ql/lib/codeql/ruby/dataflow/internal/tainttrackingforlibraries/TaintTrackingImpl.qll",
64+
"swift/ql/lib/codeql/swift/dataflow/internal/tainttracking1/TaintTrackingImpl.qll"
6265
],
6366
"DataFlow Java/C++/C#/Python Consistency checks": [
6467
"java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplConsistency.qll",
6568
"cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplConsistency.qll",
6669
"cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplConsistency.qll",
6770
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplConsistency.qll",
6871
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImplConsistency.qll",
69-
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplConsistency.qll"
72+
"ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplConsistency.qll",
73+
"swift/ql/lib/codeql/swift/dataflow/internal/DataFlowImplConsistency.qll"
7074
],
7175
"DataFlow Java/C# Flow Summaries": [
7276
"java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll",
@@ -459,7 +463,8 @@
459463
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/basessa/SsaImplCommon.qll",
460464
"csharp/ql/lib/semmle/code/cil/internal/SsaImplCommon.qll",
461465
"ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImplCommon.qll",
462-
"cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImplCommon.qll"
466+
"cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImplCommon.qll",
467+
"swift/ql/lib/codeql/swift/dataflow/internal/SsaImplCommon.qll"
463468
],
464469
"CryptoAlgorithms Python/JS/Ruby": [
465470
"javascript/ql/lib/semmle/javascript/security/CryptoAlgorithms.qll",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Provides classes for performing local (intra-procedural) and
3+
* global (inter-procedural) data flow analyses.
4+
*/
5+
module DataFlow {
6+
import internal.DataFlowImpl
7+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
private import swift
2+
private import DataFlowPrivate
3+
4+
newtype TReturnKind = TNormalReturnKind()
5+
6+
/**
7+
* Gets a node that can read the value returned from `call` with return kind
8+
* `kind`.
9+
*/
10+
OutNode getAnOutNode(DataFlowCall call, ReturnKind kind) { call = result.getCall(kind) }
11+
12+
/**
13+
* A return kind. A return kind describes how a value can be returned
14+
* from a callable.
15+
*/
16+
abstract class ReturnKind extends TReturnKind {
17+
/** Gets a textual representation of this position. */
18+
abstract string toString();
19+
}
20+
21+
/**
22+
* A value returned from a callable using a `return` statement or an expression
23+
* body, that is, a "normal" return.
24+
*/
25+
class NormalReturnKind extends ReturnKind, TNormalReturnKind {
26+
override string toString() { result = "return" }
27+
}
28+
29+
/**
30+
* A callable. This includes callables from source code, as well as callables
31+
* defined in library code.
32+
*/
33+
class DataFlowCallable extends TDataFlowCallable {
34+
/** Gets a textual representation of this callable. */
35+
string toString() { none() }
36+
37+
/** Gets the location of this callable. */
38+
Location getLocation() { none() }
39+
}
40+
41+
/**
42+
* A call. This includes calls from source code, as well as call(back)s
43+
* inside library callables with a flow summary.
44+
*/
45+
class DataFlowCall extends TDataFlowCall {
46+
/** Gets the enclosing callable. */
47+
DataFlowCallable getEnclosingCallable() { none() }
48+
49+
/** Gets a textual representation of this call. */
50+
string toString() { none() }
51+
52+
/** Gets the location of this call. */
53+
Location getLocation() { none() }
54+
55+
/**
56+
* Holds if this element is at the specified location.
57+
* The location spans column `startcolumn` of line `startline` to
58+
* column `endcolumn` of line `endline` in file `filepath`.
59+
* For more information, see
60+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries).
61+
*/
62+
predicate hasLocationInfo(
63+
string filepath, int startline, int startcolumn, int endline, int endcolumn
64+
) {
65+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
66+
}
67+
}
68+
69+
cached
70+
private module Cached {
71+
cached
72+
newtype TDataFlowCallable = TODO_TDataFlowCallable()
73+
74+
cached
75+
newtype TDataFlowCall = TODO_TDataFlowCall()
76+
77+
/** Gets a viable run-time target for the call `call`. */
78+
cached
79+
DataFlowCallable viableCallable(DataFlowCall call) { none() }
80+
81+
cached
82+
newtype TArgumentPosition = TODO_TArgumentPosition()
83+
84+
cached
85+
newtype TParameterPosition = TODO_TParameterPosition()
86+
}
87+
88+
import Cached
89+
90+
/**
91+
* Holds if the set of viable implementations that can be called by `call`
92+
* might be improved by knowing the call context.
93+
*/
94+
predicate mayBenefitFromCallContext(DataFlowCall call, DataFlowCallable c) { none() }
95+
96+
/**
97+
* Gets a viable dispatch target of `call` in the context `ctx`. This is
98+
* restricted to those `call`s for which a context might make a difference.
99+
*/
100+
DataFlowCallable viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) { none() }
101+
102+
/** A parameter position. */
103+
class ParameterPosition extends TParameterPosition {
104+
/** Gets a textual representation of this position. */
105+
string toString() { none() }
106+
}
107+
108+
/** An argument position. */
109+
class ArgumentPosition extends TArgumentPosition {
110+
/** Gets a textual representation of this position. */
111+
string toString() { none() }
112+
}
113+
114+
/** Holds if arguments at position `apos` match parameters at position `ppos`. */
115+
pragma[inline]
116+
predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) { none() }

0 commit comments

Comments
 (0)