Skip to content

Commit 1bb7125

Browse files
committed
unified: Move mayWriteBackViaSetterCall into swift plugin
This was accidentally put outside the plugin
1 parent 8ebaab9 commit 1bb7125

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPlugin.qll‎

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
private import unified
66
private import AllDataFlow
77
private import codeql.util.Unit
8-
private import codeql.unified.internal.ExprPositions
9-
private import codeql.unified.internal.typeinference.TypeInference as T
108

119
private module Plugins {
1210
private import DataFlowPluginSwift
@@ -36,37 +34,7 @@ class DataFlowPlugin extends Unit {
3634
* `expr` is an expression in getter position, such as a member access.
3735
*/
3836
bindingset[expr]
39-
predicate mayWriteBackViaSetterCall(Expr expr) {
40-
isInWriteBackPosition(expr)
41-
// TODO: Check that 'expr' has a value type. Reference types don't cause writebacks.
42-
}
43-
}
44-
45-
/**
46-
* Holds if `expr` is target of an assignment or 'inout' argument,
47-
* or the base of such an expression, e.g. `x` in `x.f1.f2 = foo()`
48-
*/
49-
private predicate isInWriteBackPosition(Expr expr) {
50-
isInAssignmentContext(expr, _)
51-
or
52-
// Arguments to an 'inout' parameter must be prefixed with '&'
53-
exists(UnaryExpr unary |
54-
unary.getOperator().(PrefixOperator).getValue() = "&" and
55-
unary.getOperand() = expr
56-
// TODO: support custom operators with an 'inout' parameter, which lack the '&' indicator
57-
)
58-
or
59-
// The receiver of a call to a 'mutating' function counts as an 'inout' argument
60-
exists(CallExpr call, Callable target |
61-
target = T::resolveCallTarget(call) and
62-
target.hasModifier("mutating") and
63-
expr = call.getCallee().(MemberAccessExpr).getBase()
64-
)
65-
or
66-
exists(MemberAccessExpr member |
67-
isInWriteBackPosition(member) and
68-
expr = member.getBase()
69-
)
37+
predicate mayWriteBackViaSetterCall(Expr expr) { none() }
7038
}
7139

7240
/**

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
private import unified
66
private import AllDataFlow
7+
private import codeql.unified.internal.ExprPositions
8+
private import codeql.unified.internal.typeinference.TypeInference as T
79

810
private class SwiftDataFlowPlugin extends DataFlowPlugin {
911
// Note: For now we assume all code is Swift, but in the future we must restrict these rules to Swift-files
@@ -13,7 +15,10 @@ private class SwiftDataFlowPlugin extends DataFlowPlugin {
1315

1416
// Swift writes back mutated values of computed properties via their setter
1517
bindingset[expr]
16-
override predicate mayWriteBackViaSetterCall(Expr expr) { any() }
18+
override predicate mayWriteBackViaSetterCall(Expr expr) {
19+
isInWriteBackPosition(expr)
20+
// TODO: Check that 'expr' has a value type. Reference types don't cause writebacks.
21+
}
1722

1823
override predicate exprStep(Expr expr1, Expr expr2, boolean mustFlow) {
1924
mustFlow = true and
@@ -90,3 +95,30 @@ private class SwiftDataFlowPlugin extends DataFlowPlugin {
9095
)
9196
}
9297
}
98+
99+
/**
100+
* Holds if `expr` is target of an assignment or 'inout' argument,
101+
* or the base of such an expression, e.g. `x` in `x.f1.f2 = foo()`
102+
*/
103+
private predicate isInWriteBackPosition(Expr expr) {
104+
isInAssignmentContext(expr, _)
105+
or
106+
// Arguments to an 'inout' parameter must be prefixed with '&'
107+
exists(UnaryExpr unary |
108+
unary.getOperator().(PrefixOperator).getValue() = "&" and
109+
unary.getOperand() = expr
110+
// TODO: support custom operators with an 'inout' parameter, which lack the '&' indicator
111+
)
112+
or
113+
// The receiver of a call to a 'mutating' function counts as an 'inout' argument
114+
exists(CallExpr call, Callable target |
115+
target = T::resolveCallTarget(call) and
116+
target.hasModifier("mutating") and
117+
expr = call.getCallee().(MemberAccessExpr).getBase()
118+
)
119+
or
120+
exists(MemberAccessExpr member |
121+
isInWriteBackPosition(member) and
122+
expr = member.getBase()
123+
)
124+
}

0 commit comments

Comments
 (0)