Skip to content

Commit c9a0067

Browse files
committed
Swift: Remove flow in cases with multiple variables.
1 parent 2c35af5 commit c9a0067

File tree

4 files changed

+4
-18
lines changed

4 files changed

+4
-18
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ module Ssa {
169169
exists(VarDecl var, SsaInput::BasicBlock bb, int blockIndex, ConditionElement ce, Expr init |
170170
this.definesAt(var, bb, blockIndex) and
171171
ce.getPattern() = bb.getNode(blockIndex).getNode().asAstNode() and
172-
init = ce.getInitializer()
172+
init = ce.getInitializer() and
173+
strictcount(Ssa::WriteDefinition alt | alt.definesAt(_, bb, blockIndex)) = 1 // exclude cases where there are multiple writes from the same pattern, this is at best taint flow.
173174
|
174175
value.getNode().asAstNode() = init
175176
)

swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ edges
142142
| test.swift:360:15:360:15 | t2 [Tuple element at index 0] : | test.swift:360:15:360:18 | .0 |
143143
| test.swift:361:15:361:15 | t2 [Tuple element at index 1] : | test.swift:361:15:361:18 | .1 |
144144
| test.swift:439:13:439:28 | call to optionalSource() : | test.swift:442:19:442:19 | a |
145-
| test.swift:455:21:455:29 | call to source2() : | test.swift:456:19:456:19 | x |
146-
| test.swift:455:21:455:29 | call to source2() : | test.swift:457:19:457:19 | y |
147145
nodes
148146
| file://:0:0:0:0 | .a [x] : | semmle.label | .a [x] : |
149147
| file://:0:0:0:0 | .x : | semmle.label | .x : |
@@ -302,9 +300,6 @@ nodes
302300
| test.swift:361:15:361:18 | .1 | semmle.label | .1 |
303301
| test.swift:439:13:439:28 | call to optionalSource() : | semmle.label | call to optionalSource() : |
304302
| test.swift:442:19:442:19 | a | semmle.label | a |
305-
| test.swift:455:21:455:29 | call to source2() : | semmle.label | call to source2() : |
306-
| test.swift:456:19:456:19 | x | semmle.label | x |
307-
| test.swift:457:19:457:19 | y | semmle.label | y |
308303
subpaths
309304
| test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:31:75:32 | [post] &... : |
310305
| test.swift:114:19:114:19 | arg : | test.swift:109:9:109:14 | arg : | test.swift:110:12:110:12 | arg : | test.swift:114:12:114:22 | call to ... : |
@@ -386,5 +381,3 @@ subpaths
386381
| test.swift:360:15:360:18 | .0 | test.swift:351:18:351:25 | call to source() : | test.swift:360:15:360:18 | .0 | result |
387382
| test.swift:361:15:361:18 | .1 | test.swift:351:31:351:38 | call to source() : | test.swift:361:15:361:18 | .1 | result |
388383
| test.swift:442:19:442:19 | a | test.swift:259:12:259:19 | call to source() : | test.swift:442:19:442:19 | a | result |
389-
| test.swift:456:19:456:19 | x | test.swift:455:21:455:29 | call to source2() : | test.swift:456:19:456:19 | x | result |
390-
| test.swift:457:19:457:19 | y | test.swift:455:21:455:29 | call to source2() : | test.swift:457:19:457:19 | y | result |

swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@
327327
| test.swift:387:32:387:32 | a | test.swift:390:37:390:37 | a |
328328
| test.swift:390:13:390:33 | SSA def(x) | test.swift:391:19:391:19 | x |
329329
| test.swift:390:13:390:33 | SSA def(y) | test.swift:392:19:392:19 | y |
330-
| test.swift:390:37:390:37 | a | test.swift:390:13:390:33 | SSA def(x) |
331-
| test.swift:390:37:390:37 | a | test.swift:390:13:390:33 | SSA def(y) |
332330
| test.swift:390:37:390:37 | a | test.swift:407:32:407:32 | a |
333331
| test.swift:395:9:395:13 | SSA def(b) | test.swift:397:12:397:12 | b |
334332
| test.swift:395:22:395:40 | call to ... | test.swift:395:9:395:13 | SSA def(b) |
@@ -340,8 +338,6 @@
340338
| test.swift:407:32:407:32 | a | test.swift:410:37:410:37 | a |
341339
| test.swift:410:13:410:33 | SSA def(x) | test.swift:411:19:411:19 | x |
342340
| test.swift:410:13:410:33 | SSA def(y) | test.swift:412:19:412:19 | y |
343-
| test.swift:410:37:410:37 | a | test.swift:410:13:410:33 | SSA def(x) |
344-
| test.swift:410:37:410:37 | a | test.swift:410:13:410:33 | SSA def(y) |
345341
| test.swift:410:37:410:37 | a | test.swift:427:32:427:32 | a |
346342
| test.swift:415:9:415:9 | SSA def(c) | test.swift:417:12:417:12 | c |
347343
| test.swift:415:13:415:38 | call to ... | test.swift:415:9:415:9 | SSA def(c) |
@@ -353,8 +349,6 @@
353349
| test.swift:427:32:427:32 | a | test.swift:430:37:430:37 | a |
354350
| test.swift:430:13:430:33 | SSA def(x) | test.swift:431:19:431:19 | x |
355351
| test.swift:430:13:430:33 | SSA def(y) | test.swift:432:19:432:19 | y |
356-
| test.swift:430:37:430:37 | a | test.swift:430:13:430:33 | SSA def(x) |
357-
| test.swift:430:37:430:37 | a | test.swift:430:13:430:33 | SSA def(y) |
358352
| test.swift:438:21:438:27 | SSA def(y) | test.swift:441:27:441:27 | y |
359353
| test.swift:438:21:438:27 | SSA def(y) | test.swift:446:22:446:22 | y |
360354
| test.swift:438:21:438:27 | y | test.swift:438:21:438:27 | SSA def(y) |
@@ -372,5 +366,3 @@
372366
| test.swift:448:10:448:37 | SSA def(b) | test.swift:450:19:450:19 | b |
373367
| test.swift:455:8:455:17 | SSA def(x) | test.swift:456:19:456:19 | x |
374368
| test.swift:455:8:455:17 | SSA def(y) | test.swift:457:19:457:19 | y |
375-
| test.swift:455:21:455:29 | call to source2() | test.swift:455:8:455:17 | SSA def(x) |
376-
| test.swift:455:21:455:29 | call to source2() | test.swift:455:8:455:17 | SSA def(y) |

swift/ql/test/library-tests/dataflow/dataflow/test.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func testOptionals2(y: Int?) {
453453
}
454454

455455
if let (x, y) = source2() {
456-
sink(arg: x) // $ flow=455
457-
sink(arg: y) // $ flow=455
456+
sink(arg: x) // (taint but not data flow)
457+
sink(arg: y) // (taint but not data flow)
458458
}
459459
}

0 commit comments

Comments
 (0)