From 711552be17b939020791aa7cdfa992d0a345a40b Mon Sep 17 00:00:00 2001 From: Asger F Date: Mon, 30 Nov 2026 13:52:10 +0100 Subject: [PATCH 1/5] Swift: Add basic optional chaining support Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../extractor/src/languages/swift/swift.rs | 10 +- .../closures/closure-with-capture-list.output | 7 +- .../nested-enum-case-pattern.output | 7 +- .../optional-chaining.output | 14 ++- .../2026-11-30-optional-chaining.md | 4 + .../internal/dataflow/DataFlowPluginSwift.qll | 2 +- .../TypeInferencePluginSwift.qll | 8 ++ .../dataflow/optional-chaining.swift | 27 +++++ .../test/library-tests/dataflow/test.expected | 50 ++++++++ .../type-inference/optional-chaining.swift | 24 ++++ .../type-inference/type-inference.expected | 111 ++++++++++++++++++ 11 files changed, 251 insertions(+), 13 deletions(-) create mode 100644 unified/ql/lib/change-notes/2026-11-30-optional-chaining.md create mode 100644 unified/ql/test/library-tests/dataflow/optional-chaining.swift create mode 100644 unified/ql/test/library-tests/type-inference/optional-chaining.swift diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 2582955ab8d7..35230d48262b 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -63,7 +63,7 @@ struct SwiftContext { /// in the correct context. in_function_type: bool, /// True while translating a pattern. Optional chaining in this context is - /// represented as an `Optional.some` call rather than being unwrapped. + /// represented as an `Optional.some` call rather than a postfix operator. in_pattern: bool, /// True when a conditional compilation block should be translated into an /// if expression. @@ -1537,8 +1537,8 @@ fn translation_rules() -> Vec> { } ), // ---- Optionals and errors ---- - // Optional chaining — unwrap the marker - rule!((optionalChainingExpr expression: @inner) => expr { + // Optional patterns wrap a value; optional chaining unwraps it. + rule!((optionalChainingExpr expression: @inner questionMark: @mark) => expr { let inner = ctx .translate(inner) .into_iter() @@ -1551,7 +1551,9 @@ fn translation_rules() -> Vec> { member_name_node: (identifier "some")) argument: (argument value: {inner}))) } else { - inner + tree!((unary_expr + operator: (postfix_operator "?" location: {mark}) + operand: {inner})) } }), // try/try?/try! expr → unary_expr with operator "try", "try?" or "try!" diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output index 573498825bc0..23c144c55836 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output @@ -79,6 +79,9 @@ top_level source="⟨body⟩" stmt: call_expr source="⟨callee⟩()" callee: - member_access_expr source="⟨base⟩?.⟨member_name_node⟩" - base: identifier "self" source="self" + member_access_expr source="⟨base⟩.⟨member_name_node⟩" + base: + unary_expr source="⟨operand⟩⟨operator⟩" + operand: identifier "self" source="self" + operator: postfix_operator "?" source="?" member_name_node: identifier "doThing" source="doThing" diff --git a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output index ea814c00d53b..a2a3943b9689 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output @@ -269,8 +269,11 @@ top_level source="⟨body⟩" pattern: call_expr source="⟨callee⟩ ⟨argument⟩" callee: - member_access_expr source="⟨base⟩?.⟨member_name_node⟩" - base: identifier "values" source="values" + member_access_expr source="⟨base⟩.⟨member_name_node⟩" + base: + unary_expr source="⟨operand⟩⟨operator⟩" + operand: identifier "values" source="values" + operator: postfix_operator "?" source="?" member_name_node: identifier "map" source="map" argument: argument source="⟨value⟩" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output index 2fb5be96bc8f..c6100efc8629 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output @@ -51,9 +51,15 @@ top_level source="⟨body⟩" modifier: modifier "let" source="let" pattern: identifier "n" source="n" value: - member_access_expr source="⟨base⟩?.⟨member_name_node⟩" + member_access_expr source="⟨base⟩.⟨member_name_node⟩" base: - member_access_expr source="⟨base⟩?.⟨member_name_node⟩" - base: identifier "obj" source="obj" - member_name_node: identifier "foo" source="foo" + unary_expr source="⟨operand⟩⟨operator⟩" + operand: + member_access_expr source="⟨base⟩.⟨member_name_node⟩" + base: + unary_expr source="⟨operand⟩⟨operator⟩" + operand: identifier "obj" source="obj" + operator: postfix_operator "?" source="?" + member_name_node: identifier "foo" source="foo" + operator: postfix_operator "?" source="?" member_name_node: identifier "bar" source="bar" diff --git a/unified/ql/lib/change-notes/2026-11-30-optional-chaining.md b/unified/ql/lib/change-notes/2026-11-30-optional-chaining.md new file mode 100644 index 000000000000..d48e0bcffe24 --- /dev/null +++ b/unified/ql/lib/change-notes/2026-11-30-optional-chaining.md @@ -0,0 +1,4 @@ +--- +category: feature +--- +* Added basic Swift optional-chaining support to the unified library. diff --git a/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll b/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll index 4538858ba7a2..46c18e24c4c1 100644 --- a/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll +++ b/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll @@ -31,7 +31,7 @@ private class SwiftDataFlowPlugin extends DataFlowPlugin { exists(UnaryExpr expr | expr.getOperator().(PrefixOperator).getValue() = "&" or - expr.getOperator().(PostfixOperator).getValue() = "!" + expr.getOperator().(PostfixOperator).getValue() = ["!", "?"] | expr1 = expr.getOperand() and expr2 = expr diff --git a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll index ecb52be938fa..511c3c1f4e32 100644 --- a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll +++ b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll @@ -152,6 +152,14 @@ private class SwiftTypeInferencePlugin extends Plugin::TypeInferencePlugin { prefix1.isEmpty() and prefix2.isEmpty() ) + or + n2 = + any(UnaryExpr expr | + n1 = expr.getOperand() and + expr.getOperator().(PostfixOperator).getValue() = "?" and + prefix1 = TypePath::singleton(any(OptionalType t).getPositionalTypeParameter(0)) and + prefix2.isEmpty() + ) } override Type inferType(AstNode n, TypePath path) { diff --git a/unified/ql/test/library-tests/dataflow/optional-chaining.swift b/unified/ql/test/library-tests/dataflow/optional-chaining.swift new file mode 100644 index 000000000000..68169382784f --- /dev/null +++ b/unified/ql/test/library-tests/dataflow/optional-chaining.swift @@ -0,0 +1,27 @@ +class OptionalChainBox { + var value: String = "" + var next: OptionalChainBox? + + func getValue() -> String { + return value + } +} + +func testOptionalChaining() { + let box: OptionalChainBox? = Optional.some(OptionalChainBox()) + box?.value = source("optional.field") + sink(box?.value) // $ hasValueFlow=optional.field + sink(box?.getValue()) // $ hasValueFlow=optional.field +} + +func testRepeatedOptionalChaining() { + let outer: OptionalChainBox? = Optional.some(OptionalChainBox()) + outer?.next = Optional.some(OptionalChainBox()) + outer?.next?.value = source("optional.chain") + sink(outer?.next?.value) // $ hasValueFlow=optional.chain +} + +func testOptionalSubscript() { + let values = Optional.some([source("optional.subscript")]) + sink(values?[0]) // $ hasValueFlow=optional.subscript +} diff --git a/unified/ql/test/library-tests/dataflow/test.expected b/unified/ql/test/library-tests/dataflow/test.expected index 1e16a1c65d65..c74f17f6ee7f 100644 --- a/unified/ql/test/library-tests/dataflow/test.expected +++ b/unified/ql/test/library-tests/dataflow/test.expected @@ -521,6 +521,27 @@ edges | modified-expressions.swift:20:20:20:35 | source(...) | modified-expressions.swift:20:9:20:16 | original | provenance | | | modified-expressions.swift:21:9:21:17 | unchecked | modified-expressions.swift:22:10:22:18 | unchecked | provenance | | | modified-expressions.swift:21:28:21:35 | original | modified-expressions.swift:21:9:21:17 | unchecked | provenance | | +| optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | optional-chaining.swift:13:10:13:12 | box [value] | provenance | | +| optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | optional-chaining.swift:14:10:14:12 | box [value] | provenance | | +| optional-chaining.swift:12:5:12:14 | ... .value | optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | provenance | | +| optional-chaining.swift:12:18:12:41 | source(...) | optional-chaining.swift:12:5:12:14 | ... .value | provenance | | +| optional-chaining.swift:13:10:13:12 | box [value] | optional-chaining.swift:13:10:13:13 | ... ? [value] | provenance | | +| optional-chaining.swift:13:10:13:13 | ... ? [value] | optional-chaining.swift:13:10:13:19 | ... .value | provenance | | +| optional-chaining.swift:14:10:14:12 | box [value] | optional-chaining.swift:6:16:6:20 | value | provenance | | +| optional-chaining.swift:14:10:14:12 | box [value] | optional-chaining.swift:14:10:14:24 | ... .getValue(...) | provenance | | +| optional-chaining.swift:20:5:20:10 | [post] ... ? [next, value] | optional-chaining.swift:21:10:21:14 | outer [next, value] | provenance | | +| optional-chaining.swift:20:5:20:15 | [post] ... .next [value] | optional-chaining.swift:20:5:20:10 | [post] ... ? [next, value] | provenance | | +| optional-chaining.swift:20:5:20:16 | [post] ... ? [value] | optional-chaining.swift:20:5:20:15 | [post] ... .next [value] | provenance | | +| optional-chaining.swift:20:5:20:22 | ... .value | optional-chaining.swift:20:5:20:16 | [post] ... ? [value] | provenance | | +| optional-chaining.swift:20:26:20:49 | source(...) | optional-chaining.swift:20:5:20:22 | ... .value | provenance | | +| optional-chaining.swift:21:10:21:14 | outer [next, value] | optional-chaining.swift:21:10:21:15 | ... ? [next, value] | provenance | | +| optional-chaining.swift:21:10:21:15 | ... ? [next, value] | optional-chaining.swift:21:10:21:20 | ... .next [value] | provenance | | +| optional-chaining.swift:21:10:21:20 | ... .next [value] | optional-chaining.swift:21:10:21:21 | ... ? [value] | provenance | | +| optional-chaining.swift:21:10:21:21 | ... ? [value] | optional-chaining.swift:21:10:21:27 | ... .value | provenance | | +| optional-chaining.swift:25:9:25:14 | values [ArrayElement] | optional-chaining.swift:26:10:26:15 | values [ArrayElement] | provenance | | +| optional-chaining.swift:25:32:25:61 | ArrayLiteral [ArrayElement] | optional-chaining.swift:25:9:25:14 | values [ArrayElement] | provenance | | +| optional-chaining.swift:25:33:25:60 | source(...) | optional-chaining.swift:25:32:25:61 | ArrayLiteral [ArrayElement] | provenance | | +| optional-chaining.swift:26:10:26:15 | values [ArrayElement] | optional-chaining.swift:26:10:26:19 | ... .subscript(...) | provenance | | | short-return.swift:7:33:7:46 | source(...) | short-return.swift:8:10:8:19 | getValue(...) | provenance | | | subscripts.swift:14:39:14:52 | source(...) | subscripts.swift:16:10:16:15 | ... .subscript(...) | provenance | | | subscripts.swift:21:19:21:21 | key | subscripts.swift:22:19:22:21 | key | provenance | | @@ -1388,6 +1409,30 @@ nodes | modified-expressions.swift:21:9:21:17 | unchecked | semmle.label | unchecked | | modified-expressions.swift:21:28:21:35 | original | semmle.label | original | | modified-expressions.swift:22:10:22:18 | unchecked | semmle.label | unchecked | +| optional-chaining.swift:6:16:6:20 | value | semmle.label | value | +| optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | semmle.label | [post] ... ? [value] | +| optional-chaining.swift:12:5:12:14 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:12:18:12:41 | source(...) | semmle.label | source(...) | +| optional-chaining.swift:13:10:13:12 | box [value] | semmle.label | box [value] | +| optional-chaining.swift:13:10:13:13 | ... ? [value] | semmle.label | ... ? [value] | +| optional-chaining.swift:13:10:13:19 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:14:10:14:12 | box [value] | semmle.label | box [value] | +| optional-chaining.swift:14:10:14:24 | ... .getValue(...) | semmle.label | ... .getValue(...) | +| optional-chaining.swift:20:5:20:10 | [post] ... ? [next, value] | semmle.label | [post] ... ? [next, value] | +| optional-chaining.swift:20:5:20:15 | [post] ... .next [value] | semmle.label | [post] ... .next [value] | +| optional-chaining.swift:20:5:20:16 | [post] ... ? [value] | semmle.label | [post] ... ? [value] | +| optional-chaining.swift:20:5:20:22 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:20:26:20:49 | source(...) | semmle.label | source(...) | +| optional-chaining.swift:21:10:21:14 | outer [next, value] | semmle.label | outer [next, value] | +| optional-chaining.swift:21:10:21:15 | ... ? [next, value] | semmle.label | ... ? [next, value] | +| optional-chaining.swift:21:10:21:20 | ... .next [value] | semmle.label | ... .next [value] | +| optional-chaining.swift:21:10:21:21 | ... ? [value] | semmle.label | ... ? [value] | +| optional-chaining.swift:21:10:21:27 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:25:9:25:14 | values [ArrayElement] | semmle.label | values [ArrayElement] | +| optional-chaining.swift:25:32:25:61 | ArrayLiteral [ArrayElement] | semmle.label | ArrayLiteral [ArrayElement] | +| optional-chaining.swift:25:33:25:60 | source(...) | semmle.label | source(...) | +| optional-chaining.swift:26:10:26:15 | values [ArrayElement] | semmle.label | values [ArrayElement] | +| optional-chaining.swift:26:10:26:19 | ... .subscript(...) | semmle.label | ... .subscript(...) | | short-return.swift:7:33:7:46 | source(...) | semmle.label | source(...) | | short-return.swift:8:10:8:19 | getValue(...) | semmle.label | getValue(...) | | subscripts.swift:14:39:14:52 | source(...) | semmle.label | source(...) | @@ -1727,6 +1772,7 @@ subpaths | fields.swift:176:28:176:63 | source(...) | fields.swift:113:22:113:26 | value | fields.swift:116:16:116:18 | box [field] | fields.swift:176:17:176:64 | ... .withField(...) [field] | | flow-summaries.swift:54:35:54:48 | source(...) | flow-summaries.swift:54:53:54:53 | y | flow-summaries.swift:54:65:54:65 | y | flow-summaries.swift:54:10:54:67 | ... .throughCallback(...) | | flow-summaries.swift:55:35:55:48 | source(...) | flow-summaries.swift:55:53:55:53 | y | flow-summaries.swift:55:65:55:71 | ... + ... | flow-summaries.swift:55:10:55:73 | ... .throughCallback(...) | +| optional-chaining.swift:14:10:14:12 | box [value] | optional-chaining.swift:6:16:6:20 | value | optional-chaining.swift:6:16:6:20 | value | optional-chaining.swift:14:10:14:24 | ... .getValue(...) | | subscripts.swift:27:12:27:25 | source(...) | subscripts.swift:21:19:21:21 | key | subscripts.swift:22:19:22:21 | key | subscripts.swift:27:10:27:26 | ... .subscript(...) | | subscripts.swift:51:5:51:15 | ... .subscript(...) | subscripts.swift:47:27:47:34 | newValue | subscripts.swift:47:19:47:23 | field | subscripts.swift:52:10:52:10 | c [field] | | subscripts.swift:51:5:51:15 | ... .subscript(...) | subscripts.swift:47:27:47:34 | newValue | subscripts.swift:47:19:47:23 | field | subscripts.swift:53:10:53:10 | c [field] | @@ -1899,6 +1945,10 @@ testFailures | modified-expressions.swift:10:10:10:17 | consumed | modified-expressions.swift:8:20:8:36 | source(...) | modified-expressions.swift:10:10:10:17 | consumed | $@ | modified-expressions.swift:8:20:8:36 | source(...) | source(...) | | modified-expressions.swift:16:10:16:15 | copied | modified-expressions.swift:14:20:14:33 | source(...) | modified-expressions.swift:16:10:16:15 | copied | $@ | modified-expressions.swift:14:20:14:33 | source(...) | source(...) | | modified-expressions.swift:22:10:22:18 | unchecked | modified-expressions.swift:20:20:20:35 | source(...) | modified-expressions.swift:22:10:22:18 | unchecked | $@ | modified-expressions.swift:20:20:20:35 | source(...) | source(...) | +| optional-chaining.swift:13:10:13:19 | ... .value | optional-chaining.swift:12:18:12:41 | source(...) | optional-chaining.swift:13:10:13:19 | ... .value | $@ | optional-chaining.swift:12:18:12:41 | source(...) | source(...) | +| optional-chaining.swift:14:10:14:24 | ... .getValue(...) | optional-chaining.swift:12:18:12:41 | source(...) | optional-chaining.swift:14:10:14:24 | ... .getValue(...) | $@ | optional-chaining.swift:12:18:12:41 | source(...) | source(...) | +| optional-chaining.swift:21:10:21:27 | ... .value | optional-chaining.swift:20:26:20:49 | source(...) | optional-chaining.swift:21:10:21:27 | ... .value | $@ | optional-chaining.swift:20:26:20:49 | source(...) | source(...) | +| optional-chaining.swift:26:10:26:19 | ... .subscript(...) | optional-chaining.swift:25:33:25:60 | source(...) | optional-chaining.swift:26:10:26:19 | ... .subscript(...) | $@ | optional-chaining.swift:25:33:25:60 | source(...) | source(...) | | short-return.swift:8:10:8:19 | getValue(...) | short-return.swift:7:33:7:46 | source(...) | short-return.swift:8:10:8:19 | getValue(...) | $@ | short-return.swift:7:33:7:46 | source(...) | source(...) | | subscripts.swift:16:10:16:15 | ... .subscript(...) | subscripts.swift:14:39:14:52 | source(...) | subscripts.swift:16:10:16:15 | ... .subscript(...) | $@ | subscripts.swift:14:39:14:52 | source(...) | source(...) | | subscripts.swift:23:24:23:31 | newValue | subscripts.swift:28:17:28:30 | source(...) | subscripts.swift:23:24:23:31 | newValue | $@ | subscripts.swift:28:17:28:30 | source(...) | source(...) | diff --git a/unified/ql/test/library-tests/type-inference/optional-chaining.swift b/unified/ql/test/library-tests/type-inference/optional-chaining.swift new file mode 100644 index 000000000000..fb1947fd3e08 --- /dev/null +++ b/unified/ql/test/library-tests/type-inference/optional-chaining.swift @@ -0,0 +1,24 @@ +class OptionalChainBox { + var value: T + var next: OptionalChainBox? + + init(value: T, next: OptionalChainBox? = nil) { + self.value = value // $ type=value:T field=OptionalChainBox.value + self.next = next // $ field=OptionalChainBox.next + } + + func getValue() -> T { + return value // $ type=value:T field=OptionalChainBox.value + } +} + +func testOptionalChaining(_ box: OptionalChainBox?) { + // Basic support unwraps each '?' without wrapping the chain's result in Optional. + let value = box?.value // $ type=value:String field=OptionalChainBox.value + let result = box?.getValue() // $ type=result:String target=OptionalChainBox.getValue + let chained = box?.next?.value // $ type=chained:String field=OptionalChainBox.next field=OptionalChainBox.value +} + +func testOptionalCall(_ callback: Optional<() -> String>) { + let result = callback?() // $ type=result:String target=Function.callAsFunction +} diff --git a/unified/ql/test/library-tests/type-inference/type-inference.expected b/unified/ql/test/library-tests/type-inference/type-inference.expected index f354307a00c1..0c1364a3d6dd 100644 --- a/unified/ql/test/library-tests/type-inference/type-inference.expected +++ b/unified/ql/test/library-tests/type-inference/type-inference.expected @@ -1052,6 +1052,49 @@ inferCertainType | nested_types.swift:367:18:367:18 | y | (parent:C).(parent:B).Ta | nested_types.swift:331:9:331:10 | Ta | | nested_types.swift:367:18:367:18 | y | (parent:C).Tb | {EXTERNAL LOCATION} | Character | | nested_types.swift:367:18:367:18 | y | Tc | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:2:7:2:11 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:3:7:3:10 | next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:3:7:3:10 | next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:3:7:3:10 | next | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:5:8:5:12 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:5:18:5:21 | next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:5:18:5:21 | next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:5:18:5:21 | next | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:6:5:6:8 | self | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:6:5:6:8 | self | T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:6:18:6:22 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:7:5:7:8 | self | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:7:5:7:8 | self | T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:7:17:7:20 | next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:7:17:7:20 | next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:7:17:7:20 | next | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:11:12:11:16 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:15:29:15:31 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:15:29:15:31 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:15:29:15:31 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:17:15:17:17 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:17:15:17:17 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:17:15:17:17 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:17:15:17:18 | ... ? | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:17:15:17:18 | ... ? | T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:18:16:18:18 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:18:16:18:18 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:18:16:18:18 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:18:16:18:19 | ... ? | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:18:16:18:19 | ... ? | T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:17:19:19 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:19:17:19:19 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:19:17:19:19 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:17:19:20 | ... ? | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:19:17:19:20 | ... ? | T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:22:25:22:32 | callback | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:22:25:22:32 | callback | Wrapped | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:22:25:22:32 | callback | Wrapped.Return | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:23:16:23:23 | callback | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:23:16:23:23 | callback | Wrapped | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:23:16:23:23 | callback | Wrapped.Return | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:23:16:23:24 | ... ? | | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:23:16:23:24 | ... ? | Return | {EXTERNAL LOCATION} | String | | overload_resolution.swift:4:17:4:17 | x | | {EXTERNAL LOCATION} | Int | | overload_resolution.swift:8:17:8:17 | x | | {EXTERNAL LOCATION} | Double | | overload_resolution.swift:12:17:12:17 | x | | {EXTERNAL LOCATION} | String | @@ -4754,6 +4797,74 @@ inferType | nested_types.swift:367:18:367:18 | y | (parent:C).Tb | {EXTERNAL LOCATION} | Character | | nested_types.swift:367:18:367:18 | y | Tc | {EXTERNAL LOCATION} | String | | nested_types.swift:367:18:367:25 | ... .getC(...) | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:2:7:2:11 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:3:7:3:10 | next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:3:7:3:10 | next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:3:7:3:10 | next | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:5:8:5:12 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:5:18:5:21 | next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:5:18:5:21 | next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:5:18:5:21 | next | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:5:52:8:3 | Block | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:5:52:8:3 | Block | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:5:52:8:3 | Block | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:6:5:6:8 | self | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:6:5:6:8 | self | T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:6:5:6:14 | ... .value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:6:5:6:22 | ... = ... | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:6:18:6:22 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:7:5:7:8 | self | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:7:5:7:8 | self | T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:7:5:7:13 | ... .next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:7:5:7:13 | ... .next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:7:5:7:13 | ... .next | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:7:5:7:20 | ... = ... | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:7:5:7:20 | ... = ... | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:7:5:7:20 | ... = ... | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:7:17:7:20 | next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:7:17:7:20 | next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:7:17:7:20 | next | Wrapped.T | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:10:24:12:3 | Block | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:11:12:11:16 | value | | optional-chaining.swift:1:24:1:24 | T | +| optional-chaining.swift:15:29:15:31 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:15:29:15:31 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:15:29:15:31 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:17:7:17:11 | value | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:17:15:17:17 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:17:15:17:17 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:17:15:17:17 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:17:15:17:18 | ... ? | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:17:15:17:18 | ... ? | T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:17:15:17:24 | ... .value | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:18:7:18:12 | result | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:18:16:18:18 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:18:16:18:18 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:18:16:18:18 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:18:16:18:19 | ... ? | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:18:16:18:19 | ... ? | T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:18:16:18:30 | ... .getValue(...) | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:7:19:13 | chained | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:17:19:19 | box | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:19:17:19:19 | box | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:19:17:19:19 | box | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:17:19:20 | ... ? | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:19:17:19:20 | ... ? | T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:17:19:25 | ... .next | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:19:17:19:25 | ... .next | Wrapped | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:19:17:19:25 | ... .next | Wrapped.T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:17:19:26 | ... ? | | optional-chaining.swift:1:1:13:1 | OptionalChainBox | +| optional-chaining.swift:19:17:19:26 | ... ? | T | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:19:17:19:32 | ... .value | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:22:25:22:32 | callback | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:22:25:22:32 | callback | Wrapped | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:22:25:22:32 | callback | Wrapped.Return | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:23:7:23:12 | result | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:23:16:23:23 | callback | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:23:16:23:23 | callback | Wrapped | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:23:16:23:23 | callback | Wrapped.Return | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:23:16:23:24 | ... ? | | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:23:16:23:24 | ... ? | Return | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:23:16:23:26 | ...(...) | | {EXTERNAL LOCATION} | String | | overload_resolution.swift:4:17:4:17 | x | | {EXTERNAL LOCATION} | Int | | overload_resolution.swift:4:35:6:3 | Block | | {EXTERNAL LOCATION} | String | | overload_resolution.swift:5:12:5:16 | "int" | | {EXTERNAL LOCATION} | String | From b1df54de124f3fb1374ad25738a3d690276bb296 Mon Sep 17 00:00:00 2001 From: Asger F Date: Wed, 2 Dec 2026 12:03:35 +0100 Subject: [PATCH 2/5] Unified: Test MaD properties through optional chains Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../library-tests/mad-builtins/test.expected | 3 +++ .../test/library-tests/mad-builtins/test.swift | 13 +++++++++++++ unified/ql/test/library-tests/mad/test.expected | 3 +++ unified/ql/test/library-tests/mad/test.swift | 17 +++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/unified/ql/test/library-tests/mad-builtins/test.expected b/unified/ql/test/library-tests/mad-builtins/test.expected index 5962215f217a..1cc95864c494 100644 --- a/unified/ql/test/library-tests/mad-builtins/test.expected +++ b/unified/ql/test/library-tests/mad-builtins/test.expected @@ -4,5 +4,8 @@ isSink | test.swift:17:5:17:21 | ... .arguments | command-injection | | test.swift:18:5:18:23 | ... .arguments | command-injection | | test.swift:21:5:21:26 | ... .arguments | command-injection | +| test.swift:38:5:38:22 | ... .arguments | command-injection | +| test.swift:39:5:39:22 | [post] ... .arguments | command-injection | isSource | test.swift:12:9:12:22 | ... .text | local | +| test.swift:37:9:37:23 | ... .text | local | diff --git a/unified/ql/test/library-tests/mad-builtins/test.swift b/unified/ql/test/library-tests/mad-builtins/test.swift index cd23768e7149..0a890c40d4ae 100644 --- a/unified/ql/test/library-tests/mad-builtins/test.swift +++ b/unified/ql/test/library-tests/mad-builtins/test.swift @@ -28,3 +28,16 @@ extension Process { arguments.append(string) // $ MISSING: isSink=command-injection } } + +func testOptionalChainingPropertiesWithoutStubs( + textField: UITextField?, + process: Process?, + string: String +) { + _ = textField?.text // $ isSource=local + process?.arguments = [string] // $ isSink=command-injection + process?.arguments.append(string) // $ isSink=command-injection + + textField?.text = string // writing a source property is not a source + _ = process?.arguments // reading a sink property is not a sink +} diff --git a/unified/ql/test/library-tests/mad/test.expected b/unified/ql/test/library-tests/mad/test.expected index a839bc8e92d3..d697f3ec896f 100644 --- a/unified/ql/test/library-tests/mad/test.expected +++ b/unified/ql/test/library-tests/mad/test.expected @@ -43,6 +43,8 @@ isSink | test.swift:276:15:276:20 | string | optional-mixed-sink | | test.swift:279:29:279:34 | string | optional-init-sink | | test.swift:280:29:280:34 | string | optional-init-sink | +| test.swift:291:5:291:22 | ... .arguments | command-injection | +| test.swift:292:5:292:22 | [post] ... .arguments | command-injection | isSource | test.swift:4:5:4:27 | String(...) | remote | | test.swift:5:5:5:44 | String(...) | remote | @@ -61,3 +63,4 @@ isSource | test.swift:210:11:210:11 | x | shorthand-source | | test.swift:232:13:232:13 | v | subscript-setter-source | | test.swift:253:11:253:11 | x | optional-source | +| test.swift:290:9:290:23 | ... .text | local | diff --git a/unified/ql/test/library-tests/mad/test.swift b/unified/ql/test/library-tests/mad/test.swift index 97efba45f33d..1cf077af6566 100644 --- a/unified/ql/test/library-tests/mad/test.swift +++ b/unified/ql/test/library-tests/mad/test.swift @@ -280,3 +280,20 @@ func testOptionalParameters(obj: OptionalTest, string: String) { _ = OptionalInit(value: string, flag: true) // $ isSink=optional-init-sink _ = OptionalInit(flag: true) // not a sink: missing required argument } + +func testOptionalChainingProperties( + textField: UITextField?, + process: Process?, + notATextField: NotATextField?, + string: String +) { + _ = textField?.text // $ isSource=local + process?.arguments = [string] // $ isSink=command-injection + process?.arguments.append(string) // $ isSink=command-injection + + textField?.text = string // writing a source property is not a source + _ = process?.arguments // reading a sink property is not a sink + _ = notATextField?.text // not a source: unrelated type + notATextField?.arguments = [string] // not a sink: unrelated type + notATextField?.arguments.append(string) // not a sink: unrelated type +} From c2b7774c31ced3709eb0c8ec77b461014b2b37cd Mon Sep 17 00:00:00 2001 From: Asger F Date: Wed, 2 Dec 2026 13:58:04 +0100 Subject: [PATCH 3/5] Unified: Remove unsupported change note Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- unified/ql/lib/change-notes/2026-11-30-optional-chaining.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 unified/ql/lib/change-notes/2026-11-30-optional-chaining.md diff --git a/unified/ql/lib/change-notes/2026-11-30-optional-chaining.md b/unified/ql/lib/change-notes/2026-11-30-optional-chaining.md deleted file mode 100644 index d48e0bcffe24..000000000000 --- a/unified/ql/lib/change-notes/2026-11-30-optional-chaining.md +++ /dev/null @@ -1,4 +0,0 @@ ---- -category: feature ---- -* Added basic Swift optional-chaining support to the unified library. From 52217955045e3e290a83cf1204c7a07f91d9d0fb Mon Sep 17 00:00:00 2001 From: Asger F Date: Thu, 3 Dec 2026 09:56:51 +0100 Subject: [PATCH 4/5] Unified: Update expectations for optional chaining Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../controlflow/basicblock-slices.expected | 10 +++++----- .../CommandInjection/CommandInjection.expected | 9 +++++++++ .../CleartextLogging/CleartextLogging.expected | 12 ++++++++---- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected index df7e456642ac..046e45112d27 100644 --- a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected +++ b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected @@ -157,10 +157,10 @@ | 129 | cfg.swift:129:3:129:27 | let n14 | 'let n14 -V n14 -> opt -^ ... ! -^ ... .self -^ ... .myInt' | | 130 | cfg.swift:130:3:130:27 | let n15 | 'let n15 -V n15 -> opt -^ ... ! -^ ... .getMyInt -^ ... .getMyInt(...)' | | 131 | cfg.swift:131:3:131:32 | let n16 | 'let n16 -V n16 -> opt -^ ... ! -^ ... .self -^ ... .getMyInt -^ ... .getMyInt(...)' | -| 133 | cfg.swift:133:3:133:22 | let n17 | 'let n17 -V n17 -> opt -^ ... .myInt' | -| 134 | cfg.swift:134:3:134:27 | let n18 | 'let n18 -V n18 -> opt -^ ... .self -^ ... .myInt' | -| 135 | cfg.swift:135:3:135:27 | let n19 | 'let n19 -V n19 -> opt -^ ... .getMyInt -^ ... .getMyInt(...)' | -| 136 | cfg.swift:136:3:136:32 | let n20 | 'let n20 -V n20 -> opt -^ ... .self -^ ... .getMyInt -^ ... .getMyInt(...)' | +| 133 | cfg.swift:133:3:133:22 | let n17 | 'let n17 -V n17 -> opt -^ ... ? -^ ... .myInt' | +| 134 | cfg.swift:134:3:134:27 | let n18 | 'let n18 -V n18 -> opt -^ ... ? -^ ... .self -^ ... .myInt' | +| 135 | cfg.swift:135:3:135:27 | let n19 | 'let n19 -V n19 -> opt -^ ... ? -^ ... .getMyInt -^ ... .getMyInt(...)' | +| 136 | cfg.swift:136:3:136:32 | let n20 | 'let n20 -V n20 -> opt -^ ... ? -^ ... .self -^ ... .getMyInt -^ ... .getMyInt(...)' | | 139 | cfg.swift:139:1:173:1 | func patterns | 'func patterns -V patterns' | | 139 | cfg.swift:139:15:139:15 | x | 'x -> Block' | | 140 | cfg.swift:140:3:141:12 | ForEachStmt | 'ForEachStmt -V 0 -> 10 -^ ... ... ...' | @@ -384,7 +384,7 @@ | 381 | cfg.swift:381:12:381:12 | c | 'c -^ ReturnExpr' | | 385 | cfg.swift:385:1:387:1 | func testOptional | 'func testOptional -V testOptional' | | 385 | cfg.swift:385:19:385:19 | c | 'c -> Block' | -| 386 | cfg.swift:386:10:386:10 | c | 'c -^ ... .getOptional -^ ... .getOptional(...) -^ ... .getMyInt -^ ... .getMyInt(...) -^ ReturnExpr' | +| 386 | cfg.swift:386:10:386:10 | c | 'c -^ ... ? -^ ... .getOptional -^ ... .getOptional(...) -^ ... ? -^ ... .getMyInt -^ ... .getMyInt(...) -^ ReturnExpr' | | 389 | cfg.swift:389:1:393:1 | func testCapture | 'func testCapture -V testCapture' | | 389 | cfg.swift:389:18:389:18 | x | 'x -> y -> Block' | | 390 | cfg.swift:390:13:390:21 | z | 'z -V z -> x -> y -^ ... + ... -> t -V t -> "literal" -^ FunctionExpr -^ ReturnExpr' | diff --git a/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected b/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected index c6df1025804b..f5ffb3494554 100644 --- a/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected +++ b/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected @@ -2,6 +2,7 @@ | CommandInjection.swift:120:2:120:20 | ... .executableURL | CommandInjection.swift:105:40:105:94 | String(...) | CommandInjection.swift:120:2:120:20 | ... .executableURL | This command depends on a $@. | CommandInjection.swift:105:40:105:94 | String(...) | user-provided value | | CommandInjection.swift:125:2:125:20 | ... .executableURL | CommandInjection.swift:105:40:105:94 | String(...) | CommandInjection.swift:125:2:125:20 | ... .executableURL | This command depends on a $@. | CommandInjection.swift:105:40:105:94 | String(...) | user-provided value | | CommandInjection.swift:126:2:126:20 | ... .executableURL | CommandInjection.swift:105:40:105:94 | String(...) | CommandInjection.swift:126:2:126:20 | ... .executableURL | This command depends on a $@. | CommandInjection.swift:105:40:105:94 | String(...) | user-provided value | +| CommandInjection.swift:131:2:131:21 | ... .executableURL | CommandInjection.swift:105:40:105:94 | String(...) | CommandInjection.swift:131:2:131:21 | ... .executableURL | This command depends on a $@. | CommandInjection.swift:105:40:105:94 | String(...) | user-provided value | | CommandInjection.swift:136:2:136:20 | ... .executableURL | CommandInjection.swift:105:40:105:94 | String(...) | CommandInjection.swift:136:2:136:20 | ... .executableURL | This command depends on a $@. | CommandInjection.swift:105:40:105:94 | String(...) | user-provided value | | CommandInjection.swift:137:2:137:20 | ... .executableURL | CommandInjection.swift:105:40:105:94 | String(...) | CommandInjection.swift:137:2:137:20 | ... .executableURL | This command depends on a $@. | CommandInjection.swift:105:40:105:94 | String(...) | user-provided value | | CommandInjection.swift:146:2:146:16 | [post] ... .arguments | CommandInjection.swift:105:40:105:94 | String(...) | CommandInjection.swift:146:2:146:16 | [post] ... .arguments | This command depends on a $@. | CommandInjection.swift:105:40:105:94 | String(...) | user-provided value | @@ -14,6 +15,7 @@ edges | CommandInjection.swift:105:12:105:31 | userControlledString | CommandInjection.swift:120:36:120:55 | userControlledString | provenance | | | CommandInjection.swift:105:12:105:31 | userControlledString | CommandInjection.swift:125:45:125:64 | userControlledString | provenance | | | CommandInjection.swift:105:12:105:31 | userControlledString | CommandInjection.swift:126:36:126:55 | userControlledString | provenance | | +| CommandInjection.swift:105:12:105:31 | userControlledString | CommandInjection.swift:131:46:131:65 | userControlledString | provenance | | | CommandInjection.swift:105:12:105:31 | userControlledString | CommandInjection.swift:136:45:136:64 | userControlledString | provenance | | | CommandInjection.swift:105:12:105:31 | userControlledString | CommandInjection.swift:137:36:137:55 | userControlledString | provenance | | | CommandInjection.swift:105:12:105:31 | userControlledString | CommandInjection.swift:146:26:146:45 | userControlledString | provenance | | @@ -30,6 +32,8 @@ edges | CommandInjection.swift:126:24:126:56 | URL(...) | CommandInjection.swift:126:2:126:20 | ... .executableURL | provenance | | | CommandInjection.swift:126:36:126:55 | userControlledString | CommandInjection.swift:126:2:126:20 | ... .executableURL | provenance | | | CommandInjection.swift:126:36:126:55 | userControlledString | CommandInjection.swift:126:24:126:56 | URL(...) | provenance | | +| CommandInjection.swift:131:25:131:66 | URL(...) | CommandInjection.swift:131:2:131:21 | ... .executableURL | provenance | | +| CommandInjection.swift:131:46:131:65 | userControlledString | CommandInjection.swift:131:25:131:66 | URL(...) | provenance | | | CommandInjection.swift:136:24:136:65 | URL(...) | CommandInjection.swift:136:2:136:20 | ... .executableURL | provenance | | | CommandInjection.swift:136:45:136:64 | userControlledString | CommandInjection.swift:136:24:136:65 | URL(...) | provenance | | | CommandInjection.swift:137:24:137:56 | URL(...) | CommandInjection.swift:137:2:137:20 | ... .executableURL | provenance | | @@ -58,6 +62,9 @@ nodes | CommandInjection.swift:126:2:126:20 | ... .executableURL | semmle.label | ... .executableURL | | CommandInjection.swift:126:24:126:56 | URL(...) | semmle.label | URL(...) | | CommandInjection.swift:126:36:126:55 | userControlledString | semmle.label | userControlledString | +| CommandInjection.swift:131:2:131:21 | ... .executableURL | semmle.label | ... .executableURL | +| CommandInjection.swift:131:25:131:66 | URL(...) | semmle.label | URL(...) | +| CommandInjection.swift:131:46:131:65 | userControlledString | semmle.label | userControlledString | | CommandInjection.swift:136:2:136:20 | ... .executableURL | semmle.label | ... .executableURL | | CommandInjection.swift:136:24:136:65 | URL(...) | semmle.label | URL(...) | | CommandInjection.swift:136:45:136:64 | userControlledString | semmle.label | userControlledString | @@ -77,3 +84,5 @@ nodes | CommandInjection.swift:163:41:163:74 | ... ! | semmle.label | ... ! | | CommandInjection.swift:163:53:163:72 | userControlledString | semmle.label | userControlledString | subpaths +testFailures +| CommandInjection.swift:131:2:131:21 | ... .executableURL | Fixed missing result: Alert | diff --git a/unified/ql/test/query-tests/security/CWE-312/CleartextLogging/CleartextLogging.expected b/unified/ql/test/query-tests/security/CWE-312/CleartextLogging/CleartextLogging.expected index 82bdf5feef1c..67c086da5344 100644 --- a/unified/ql/test/query-tests/security/CWE-312/CleartextLogging/CleartextLogging.expected +++ b/unified/ql/test/query-tests/security/CWE-312/CleartextLogging/CleartextLogging.expected @@ -118,8 +118,9 @@ edges | CleartextLoggingTest.swift:293:8:293:26 | ... .optionalPassword | CleartextLoggingTest.swift:293:8:293:27 | ... ! | provenance | | | CleartextLoggingTest.swift:293:8:293:27 | ... ! | CleartextLoggingTest.swift:293:8:293:33 | ... .value | provenance | | | CleartextLoggingTest.swift:293:8:293:27 | ... ! | CleartextLoggingTest.swift:293:8:293:33 | ... .value | provenance | Config | -| CleartextLoggingTest.swift:294:9:294:27 | ... .optionalPassword | CleartextLoggingTest.swift:294:9:294:34 | ... .value | provenance | | -| CleartextLoggingTest.swift:294:9:294:27 | ... .optionalPassword | CleartextLoggingTest.swift:294:9:294:34 | ... .value | provenance | Config | +| CleartextLoggingTest.swift:294:9:294:27 | ... .optionalPassword | CleartextLoggingTest.swift:294:9:294:28 | ... ? | provenance | | +| CleartextLoggingTest.swift:294:9:294:28 | ... ? | CleartextLoggingTest.swift:294:9:294:34 | ... .value | provenance | | +| CleartextLoggingTest.swift:294:9:294:28 | ... ? | CleartextLoggingTest.swift:294:9:294:34 | ... .value | provenance | Config | | CleartextLoggingTest.swift:294:9:294:34 | ... .value | CleartextLoggingTest.swift:294:8:294:36 | ... ! | provenance | | | CleartextLoggingTest.swift:297:8:297:18 | ... .password | CleartextLoggingTest.swift:297:8:297:27 | ... .getValue | provenance | | | CleartextLoggingTest.swift:297:8:297:18 | ... .password | CleartextLoggingTest.swift:297:8:297:27 | ... .getValue | provenance | Config | @@ -135,8 +136,9 @@ edges | CleartextLoggingTest.swift:299:8:299:27 | ... ! | CleartextLoggingTest.swift:299:8:299:36 | ... .getValue | provenance | | | CleartextLoggingTest.swift:299:8:299:27 | ... ! | CleartextLoggingTest.swift:299:8:299:36 | ... .getValue | provenance | Config | | CleartextLoggingTest.swift:299:8:299:36 | ... .getValue | CleartextLoggingTest.swift:299:8:299:38 | ... .getValue(...) | provenance | Config | -| CleartextLoggingTest.swift:300:8:300:26 | ... .optionalPassword | CleartextLoggingTest.swift:300:8:300:36 | ... .getValue | provenance | | -| CleartextLoggingTest.swift:300:8:300:26 | ... .optionalPassword | CleartextLoggingTest.swift:300:8:300:36 | ... .getValue | provenance | Config | +| CleartextLoggingTest.swift:300:8:300:26 | ... .optionalPassword | CleartextLoggingTest.swift:300:8:300:27 | ... ? | provenance | | +| CleartextLoggingTest.swift:300:8:300:27 | ... ? | CleartextLoggingTest.swift:300:8:300:36 | ... .getValue | provenance | | +| CleartextLoggingTest.swift:300:8:300:27 | ... ? | CleartextLoggingTest.swift:300:8:300:36 | ... .getValue | provenance | Config | | CleartextLoggingTest.swift:300:8:300:36 | ... .getValue | CleartextLoggingTest.swift:300:8:300:38 | ... .getValue(...) | provenance | Config | | CleartextLoggingTest.swift:300:8:300:38 | ... .getValue(...) | CleartextLoggingTest.swift:300:8:300:44 | ... ?? ... | provenance | | | CleartextLoggingTest.swift:323:8:323:15 | password | CleartextLoggingTest.swift:323:22:323:31 | [post] & ... | provenance | | @@ -247,6 +249,7 @@ nodes | CleartextLoggingTest.swift:293:8:293:33 | ... .value | semmle.label | ... .value | | CleartextLoggingTest.swift:294:8:294:36 | ... ! | semmle.label | ... ! | | CleartextLoggingTest.swift:294:9:294:27 | ... .optionalPassword | semmle.label | ... .optionalPassword | +| CleartextLoggingTest.swift:294:9:294:28 | ... ? | semmle.label | ... ? | | CleartextLoggingTest.swift:294:9:294:34 | ... .value | semmle.label | ... .value | | CleartextLoggingTest.swift:297:8:297:18 | ... .password | semmle.label | ... .password | | CleartextLoggingTest.swift:297:8:297:27 | ... .getValue | semmle.label | ... .getValue | @@ -261,6 +264,7 @@ nodes | CleartextLoggingTest.swift:299:8:299:36 | ... .getValue | semmle.label | ... .getValue | | CleartextLoggingTest.swift:299:8:299:38 | ... .getValue(...) | semmle.label | ... .getValue(...) | | CleartextLoggingTest.swift:300:8:300:26 | ... .optionalPassword | semmle.label | ... .optionalPassword | +| CleartextLoggingTest.swift:300:8:300:27 | ... ? | semmle.label | ... ? | | CleartextLoggingTest.swift:300:8:300:36 | ... .getValue | semmle.label | ... .getValue | | CleartextLoggingTest.swift:300:8:300:38 | ... .getValue(...) | semmle.label | ... .getValue(...) | | CleartextLoggingTest.swift:300:8:300:44 | ... ?? ... | semmle.label | ... ?? ... | From 3372fa9dee11b3b3d0175637551e907cab4c21ad Mon Sep 17 00:00:00 2001 From: Asger F Date: Thu, 3 Dec 2026 11:10:44 +0100 Subject: [PATCH 5/5] Unified: Fix optional-chain setter and weak-capture inference Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../extractor/src/languages/swift/swift.rs | 12 +- .../closures/closure-with-capture-list.output | 12 +- .../internal/dataflow/DataFlowPluginSwift.qll | 7 + .../test/library-tests/dataflow/capture.swift | 10 ++ .../dataflow/optional-chaining.swift | 24 +++ .../test/library-tests/dataflow/test.expected | 169 +++++++++++------- .../type-inference/optional-chaining.swift | 10 ++ .../type-inference/type-inference.expected | 22 +++ .../CommandInjection.expected | 2 - .../CommandInjection/CommandInjection.swift | 2 +- 10 files changed, 203 insertions(+), 67 deletions(-) diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 35230d48262b..7ac4d73c53db 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -1205,11 +1205,19 @@ fn translation_rules() -> Vec> { modifier: [(modifier #{spec})] pattern: (identifier #{name}) value: { - // Expand [x] into [x = x] - if let Some(val) = val { + let value = if let Some(val) = val { ctx.translate_one(val) } else { tree!((identifier #{name})) + }; + if spec.map_or_default(|s| ctx.source_text(s) == "weak") { + tree!((call_expr + callee: (member_access_expr + base: (identifier "Optional") + member_name_node: (identifier "some")) + argument: (argument value: {value}))) + } else { + value } }) ), diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output index 23c144c55836..cc2f41b0a06a 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output @@ -70,10 +70,18 @@ top_level source="⟨body⟩" value: function_expr source="{ [⟨capture_declaration⟩] in ⟨body⟩ }" capture_declaration: - variable_declaration source="⟨modifier⟩ ⟨pattern⟩⟨value⟩" + variable_declaration source="⟨modifier⟩⟨value⟩⟨pattern⟩" modifier: modifier "weak" source="weak" pattern: identifier "self" source="self" - value: identifier "self" source="self" + value: + call_expr source="weak ⟨argument⟩" + callee: + member_access_expr source="" + base: identifier "Optional" source="" + member_name_node: identifier "some" source="" + argument: + argument source="⟨value⟩" + value: identifier "self" source="self" body: block source="⟨stmt⟩" stmt: diff --git a/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll b/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll index 46c18e24c4c1..a4b5c419f56f 100644 --- a/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll +++ b/unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll @@ -163,4 +163,11 @@ private predicate isInWriteBackPosition(Expr expr, boolean direct) { expr = call.getCallee() and direct = false ) + or + exists(UnaryExpr unary | + unary.getOperator().(PostfixOperator).getValue() = "?" and + isInWriteBackPosition(unary, _) and + expr = unary.getOperand() and + direct = false + ) } diff --git a/unified/ql/test/library-tests/dataflow/capture.swift b/unified/ql/test/library-tests/dataflow/capture.swift index d446b472aae6..4c6c658f9539 100644 --- a/unified/ql/test/library-tests/dataflow/capture.swift +++ b/unified/ql/test/library-tests/dataflow/capture.swift @@ -209,6 +209,16 @@ class C { closure() } + func capture_weak_self_optional_call() { + x = source("C.5") + let closure = { [weak self] in + sink(self?.getX() ?? "") // $ hasValueFlow=C.5 + } + closure() + } + + func getX() -> String { x } + func capture_unowned_self() { x = source("C.4") let closure = { [unowned self] in diff --git a/unified/ql/test/library-tests/dataflow/optional-chaining.swift b/unified/ql/test/library-tests/dataflow/optional-chaining.swift index 68169382784f..0a99cdb1d8ed 100644 --- a/unified/ql/test/library-tests/dataflow/optional-chaining.swift +++ b/unified/ql/test/library-tests/dataflow/optional-chaining.swift @@ -7,6 +7,23 @@ class OptionalChainBox { } } +struct OptionalChainValue { + var stored: String + var computed: String { + get { stored } + set { stored = newValue } + } +} + +class OptionalChainContainer { + private var storedValue: OptionalChainValue? = nil + + var optionalValue: OptionalChainValue? { + get { storedValue } + set { storedValue = newValue } + } +} + func testOptionalChaining() { let box: OptionalChainBox? = Optional.some(OptionalChainBox()) box?.value = source("optional.field") @@ -14,6 +31,13 @@ func testOptionalChaining() { sink(box?.getValue()) // $ hasValueFlow=optional.field } +func testOptionalValueTypeSetterWriteBack() { + let container = OptionalChainContainer() + container.optionalValue = Optional.some(OptionalChainValue(stored: "")) + container.optionalValue?.computed = source("optional.writeback") + sink(container.optionalValue?.stored) // $ hasValueFlow=optional.writeback +} + func testRepeatedOptionalChaining() { let outer: OptionalChainBox? = Optional.some(OptionalChainBox()) outer?.next = Optional.some(OptionalChainBox()) diff --git a/unified/ql/test/library-tests/dataflow/test.expected b/unified/ql/test/library-tests/dataflow/test.expected index c74f17f6ee7f..fd12aba5a303 100644 --- a/unified/ql/test/library-tests/dataflow/test.expected +++ b/unified/ql/test/library-tests/dataflow/test.expected @@ -207,12 +207,19 @@ edges | capture.swift:205:23:205:26 | self [x] | capture.swift:206:18:206:21 | self [x] | provenance | | | capture.swift:205:23:205:26 | self [x] | capture.swift:207:18:207:18 | x | provenance | | | capture.swift:206:18:206:21 | self [x] | capture.swift:206:18:206:23 | ... .x | provenance | | -| capture.swift:213:9:213:9 | x | capture.swift:214:34:214:37 | self [x] | provenance | | +| capture.swift:213:9:213:9 | x | capture.swift:214:31:214:34 | self [x] | provenance | | | capture.swift:213:13:213:25 | source(...) | capture.swift:213:9:213:9 | x | provenance | | -| capture.swift:214:34:214:37 | self [x] | capture.swift:214:34:214:37 | self [x] | provenance | | -| capture.swift:214:34:214:37 | self [x] | capture.swift:215:18:215:21 | self [x] | provenance | | -| capture.swift:214:34:214:37 | self [x] | capture.swift:216:18:216:18 | x | provenance | | -| capture.swift:215:18:215:21 | self [x] | capture.swift:215:18:215:23 | ... .x | provenance | | +| capture.swift:214:31:214:34 | self [x] | capture.swift:214:31:214:34 | self [x] | provenance | | +| capture.swift:214:31:214:34 | self [x] | capture.swift:215:18:215:21 | self [x] | provenance | | +| capture.swift:215:18:215:21 | self [x] | capture.swift:215:18:215:29 | ... .getX(...) | provenance | | +| capture.swift:215:18:215:21 | self [x] | capture.swift:220:29:220:29 | x | provenance | | +| capture.swift:215:18:215:29 | ... .getX(...) | capture.swift:215:18:215:35 | ... ?? ... | provenance | | +| capture.swift:223:9:223:9 | x | capture.swift:224:34:224:37 | self [x] | provenance | | +| capture.swift:223:13:223:25 | source(...) | capture.swift:223:9:223:9 | x | provenance | | +| capture.swift:224:34:224:37 | self [x] | capture.swift:224:34:224:37 | self [x] | provenance | | +| capture.swift:224:34:224:37 | self [x] | capture.swift:225:18:225:21 | self [x] | provenance | | +| capture.swift:224:34:224:37 | self [x] | capture.swift:226:18:226:18 | x | provenance | | +| capture.swift:225:18:225:21 | self [x] | capture.swift:225:18:225:23 | ... .x | provenance | | | enums.swift:12:9:12:9 | e [case1.0] | enums.swift:14:12:14:12 | e [case1.0] | provenance | | | enums.swift:12:13:12:35 | ... .case1(...) [case1.0] | enums.swift:12:9:12:9 | e [case1.0] | provenance | | | enums.swift:12:21:12:34 | source(...) | enums.swift:12:13:12:35 | ... .case1(...) [case1.0] | provenance | | @@ -521,27 +528,41 @@ edges | modified-expressions.swift:20:20:20:35 | source(...) | modified-expressions.swift:20:9:20:16 | original | provenance | | | modified-expressions.swift:21:9:21:17 | unchecked | modified-expressions.swift:22:10:22:18 | unchecked | provenance | | | modified-expressions.swift:21:28:21:35 | original | modified-expressions.swift:21:9:21:17 | unchecked | provenance | | -| optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | optional-chaining.swift:13:10:13:12 | box [value] | provenance | | -| optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | optional-chaining.swift:14:10:14:12 | box [value] | provenance | | -| optional-chaining.swift:12:5:12:14 | ... .value | optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | provenance | | -| optional-chaining.swift:12:18:12:41 | source(...) | optional-chaining.swift:12:5:12:14 | ... .value | provenance | | -| optional-chaining.swift:13:10:13:12 | box [value] | optional-chaining.swift:13:10:13:13 | ... ? [value] | provenance | | -| optional-chaining.swift:13:10:13:13 | ... ? [value] | optional-chaining.swift:13:10:13:19 | ... .value | provenance | | -| optional-chaining.swift:14:10:14:12 | box [value] | optional-chaining.swift:6:16:6:20 | value | provenance | | -| optional-chaining.swift:14:10:14:12 | box [value] | optional-chaining.swift:14:10:14:24 | ... .getValue(...) | provenance | | -| optional-chaining.swift:20:5:20:10 | [post] ... ? [next, value] | optional-chaining.swift:21:10:21:14 | outer [next, value] | provenance | | -| optional-chaining.swift:20:5:20:15 | [post] ... .next [value] | optional-chaining.swift:20:5:20:10 | [post] ... ? [next, value] | provenance | | -| optional-chaining.swift:20:5:20:16 | [post] ... ? [value] | optional-chaining.swift:20:5:20:15 | [post] ... .next [value] | provenance | | -| optional-chaining.swift:20:5:20:22 | ... .value | optional-chaining.swift:20:5:20:16 | [post] ... ? [value] | provenance | | -| optional-chaining.swift:20:26:20:49 | source(...) | optional-chaining.swift:20:5:20:22 | ... .value | provenance | | -| optional-chaining.swift:21:10:21:14 | outer [next, value] | optional-chaining.swift:21:10:21:15 | ... ? [next, value] | provenance | | -| optional-chaining.swift:21:10:21:15 | ... ? [next, value] | optional-chaining.swift:21:10:21:20 | ... .next [value] | provenance | | -| optional-chaining.swift:21:10:21:20 | ... .next [value] | optional-chaining.swift:21:10:21:21 | ... ? [value] | provenance | | -| optional-chaining.swift:21:10:21:21 | ... ? [value] | optional-chaining.swift:21:10:21:27 | ... .value | provenance | | -| optional-chaining.swift:25:9:25:14 | values [ArrayElement] | optional-chaining.swift:26:10:26:15 | values [ArrayElement] | provenance | | -| optional-chaining.swift:25:32:25:61 | ArrayLiteral [ArrayElement] | optional-chaining.swift:25:9:25:14 | values [ArrayElement] | provenance | | -| optional-chaining.swift:25:33:25:60 | source(...) | optional-chaining.swift:25:32:25:61 | ArrayLiteral [ArrayElement] | provenance | | -| optional-chaining.swift:26:10:26:15 | values [ArrayElement] | optional-chaining.swift:26:10:26:19 | ... .subscript(...) | provenance | | +| optional-chaining.swift:14:24:14:31 | newValue | optional-chaining.swift:14:15:14:20 | stored | provenance | | +| optional-chaining.swift:23:29:23:36 | newValue [stored] | optional-chaining.swift:23:15:23:25 | storedValue [stored] | provenance | | +| optional-chaining.swift:29:5:29:8 | [post] ... ? [value] | optional-chaining.swift:30:10:30:12 | box [value] | provenance | | +| optional-chaining.swift:29:5:29:8 | [post] ... ? [value] | optional-chaining.swift:31:10:31:12 | box [value] | provenance | | +| optional-chaining.swift:29:5:29:14 | ... .value | optional-chaining.swift:29:5:29:8 | [post] ... ? [value] | provenance | | +| optional-chaining.swift:29:18:29:41 | source(...) | optional-chaining.swift:29:5:29:14 | ... .value | provenance | | +| optional-chaining.swift:30:10:30:12 | box [value] | optional-chaining.swift:30:10:30:13 | ... ? [value] | provenance | | +| optional-chaining.swift:30:10:30:13 | ... ? [value] | optional-chaining.swift:30:10:30:19 | ... .value | provenance | | +| optional-chaining.swift:31:10:31:12 | box [value] | optional-chaining.swift:6:16:6:20 | value | provenance | | +| optional-chaining.swift:31:10:31:12 | box [value] | optional-chaining.swift:31:10:31:24 | ... .getValue(...) | provenance | | +| optional-chaining.swift:37:5:37:13 | [post] container [optionalValue, stored] | optional-chaining.swift:38:10:38:18 | container [optionalValue, stored] | provenance | | +| optional-chaining.swift:37:5:37:27 | [post] ... .optionalValue [stored] | optional-chaining.swift:23:29:23:36 | newValue [stored] | provenance | | +| optional-chaining.swift:37:5:37:27 | [post] ... .optionalValue [stored] | optional-chaining.swift:37:5:37:13 | [post] container [optionalValue, stored] | provenance | | +| optional-chaining.swift:37:5:37:27 | [post] ... .optionalValue [stored] | optional-chaining.swift:38:10:38:18 | container [storedValue, stored] | provenance | | +| optional-chaining.swift:37:5:37:37 | ... .computed | optional-chaining.swift:14:24:14:31 | newValue | provenance | | +| optional-chaining.swift:37:5:37:37 | ... .computed | optional-chaining.swift:37:5:37:27 | [post] ... .optionalValue [stored] | provenance | | +| optional-chaining.swift:37:41:37:68 | source(...) | optional-chaining.swift:37:5:37:37 | ... .computed | provenance | | +| optional-chaining.swift:38:10:38:18 | container [optionalValue, stored] | optional-chaining.swift:38:10:38:32 | ... .optionalValue [stored] | provenance | | +| optional-chaining.swift:38:10:38:18 | container [storedValue, stored] | optional-chaining.swift:22:15:22:25 | storedValue [stored] | provenance | | +| optional-chaining.swift:38:10:38:18 | container [storedValue, stored] | optional-chaining.swift:38:10:38:32 | ... .optionalValue [stored] | provenance | | +| optional-chaining.swift:38:10:38:32 | ... .optionalValue [stored] | optional-chaining.swift:38:10:38:33 | ... ? [stored] | provenance | | +| optional-chaining.swift:38:10:38:33 | ... ? [stored] | optional-chaining.swift:38:10:38:40 | ... .stored | provenance | | +| optional-chaining.swift:44:5:44:10 | [post] ... ? [next, value] | optional-chaining.swift:45:10:45:14 | outer [next, value] | provenance | | +| optional-chaining.swift:44:5:44:15 | [post] ... .next [value] | optional-chaining.swift:44:5:44:10 | [post] ... ? [next, value] | provenance | | +| optional-chaining.swift:44:5:44:16 | [post] ... ? [value] | optional-chaining.swift:44:5:44:15 | [post] ... .next [value] | provenance | | +| optional-chaining.swift:44:5:44:22 | ... .value | optional-chaining.swift:44:5:44:16 | [post] ... ? [value] | provenance | | +| optional-chaining.swift:44:26:44:49 | source(...) | optional-chaining.swift:44:5:44:22 | ... .value | provenance | | +| optional-chaining.swift:45:10:45:14 | outer [next, value] | optional-chaining.swift:45:10:45:15 | ... ? [next, value] | provenance | | +| optional-chaining.swift:45:10:45:15 | ... ? [next, value] | optional-chaining.swift:45:10:45:20 | ... .next [value] | provenance | | +| optional-chaining.swift:45:10:45:20 | ... .next [value] | optional-chaining.swift:45:10:45:21 | ... ? [value] | provenance | | +| optional-chaining.swift:45:10:45:21 | ... ? [value] | optional-chaining.swift:45:10:45:27 | ... .value | provenance | | +| optional-chaining.swift:49:9:49:14 | values [ArrayElement] | optional-chaining.swift:50:10:50:15 | values [ArrayElement] | provenance | | +| optional-chaining.swift:49:32:49:61 | ArrayLiteral [ArrayElement] | optional-chaining.swift:49:9:49:14 | values [ArrayElement] | provenance | | +| optional-chaining.swift:49:33:49:60 | source(...) | optional-chaining.swift:49:32:49:61 | ArrayLiteral [ArrayElement] | provenance | | +| optional-chaining.swift:50:10:50:15 | values [ArrayElement] | optional-chaining.swift:50:10:50:19 | ... .subscript(...) | provenance | | | short-return.swift:7:33:7:46 | source(...) | short-return.swift:8:10:8:19 | getValue(...) | provenance | | | subscripts.swift:14:39:14:52 | source(...) | subscripts.swift:16:10:16:15 | ... .subscript(...) | provenance | | | subscripts.swift:21:19:21:21 | key | subscripts.swift:22:19:22:21 | key | provenance | | @@ -1062,11 +1083,19 @@ nodes | capture.swift:207:18:207:18 | x | semmle.label | x | | capture.swift:213:9:213:9 | x | semmle.label | x | | capture.swift:213:13:213:25 | source(...) | semmle.label | source(...) | -| capture.swift:214:34:214:37 | self [x] | semmle.label | self [x] | -| capture.swift:214:34:214:37 | self [x] | semmle.label | self [x] | +| capture.swift:214:31:214:34 | self [x] | semmle.label | self [x] | +| capture.swift:214:31:214:34 | self [x] | semmle.label | self [x] | | capture.swift:215:18:215:21 | self [x] | semmle.label | self [x] | -| capture.swift:215:18:215:23 | ... .x | semmle.label | ... .x | -| capture.swift:216:18:216:18 | x | semmle.label | x | +| capture.swift:215:18:215:29 | ... .getX(...) | semmle.label | ... .getX(...) | +| capture.swift:215:18:215:35 | ... ?? ... | semmle.label | ... ?? ... | +| capture.swift:220:29:220:29 | x | semmle.label | x | +| capture.swift:223:9:223:9 | x | semmle.label | x | +| capture.swift:223:13:223:25 | source(...) | semmle.label | source(...) | +| capture.swift:224:34:224:37 | self [x] | semmle.label | self [x] | +| capture.swift:224:34:224:37 | self [x] | semmle.label | self [x] | +| capture.swift:225:18:225:21 | self [x] | semmle.label | self [x] | +| capture.swift:225:18:225:23 | ... .x | semmle.label | ... .x | +| capture.swift:226:18:226:18 | x | semmle.label | x | | enums.swift:12:9:12:9 | e [case1.0] | semmle.label | e [case1.0] | | enums.swift:12:13:12:35 | ... .case1(...) [case1.0] | semmle.label | ... .case1(...) [case1.0] | | enums.swift:12:21:12:34 | source(...) | semmle.label | source(...) | @@ -1410,29 +1439,43 @@ nodes | modified-expressions.swift:21:28:21:35 | original | semmle.label | original | | modified-expressions.swift:22:10:22:18 | unchecked | semmle.label | unchecked | | optional-chaining.swift:6:16:6:20 | value | semmle.label | value | -| optional-chaining.swift:12:5:12:8 | [post] ... ? [value] | semmle.label | [post] ... ? [value] | -| optional-chaining.swift:12:5:12:14 | ... .value | semmle.label | ... .value | -| optional-chaining.swift:12:18:12:41 | source(...) | semmle.label | source(...) | -| optional-chaining.swift:13:10:13:12 | box [value] | semmle.label | box [value] | -| optional-chaining.swift:13:10:13:13 | ... ? [value] | semmle.label | ... ? [value] | -| optional-chaining.swift:13:10:13:19 | ... .value | semmle.label | ... .value | -| optional-chaining.swift:14:10:14:12 | box [value] | semmle.label | box [value] | -| optional-chaining.swift:14:10:14:24 | ... .getValue(...) | semmle.label | ... .getValue(...) | -| optional-chaining.swift:20:5:20:10 | [post] ... ? [next, value] | semmle.label | [post] ... ? [next, value] | -| optional-chaining.swift:20:5:20:15 | [post] ... .next [value] | semmle.label | [post] ... .next [value] | -| optional-chaining.swift:20:5:20:16 | [post] ... ? [value] | semmle.label | [post] ... ? [value] | -| optional-chaining.swift:20:5:20:22 | ... .value | semmle.label | ... .value | -| optional-chaining.swift:20:26:20:49 | source(...) | semmle.label | source(...) | -| optional-chaining.swift:21:10:21:14 | outer [next, value] | semmle.label | outer [next, value] | -| optional-chaining.swift:21:10:21:15 | ... ? [next, value] | semmle.label | ... ? [next, value] | -| optional-chaining.swift:21:10:21:20 | ... .next [value] | semmle.label | ... .next [value] | -| optional-chaining.swift:21:10:21:21 | ... ? [value] | semmle.label | ... ? [value] | -| optional-chaining.swift:21:10:21:27 | ... .value | semmle.label | ... .value | -| optional-chaining.swift:25:9:25:14 | values [ArrayElement] | semmle.label | values [ArrayElement] | -| optional-chaining.swift:25:32:25:61 | ArrayLiteral [ArrayElement] | semmle.label | ArrayLiteral [ArrayElement] | -| optional-chaining.swift:25:33:25:60 | source(...) | semmle.label | source(...) | -| optional-chaining.swift:26:10:26:15 | values [ArrayElement] | semmle.label | values [ArrayElement] | -| optional-chaining.swift:26:10:26:19 | ... .subscript(...) | semmle.label | ... .subscript(...) | +| optional-chaining.swift:14:15:14:20 | stored | semmle.label | stored | +| optional-chaining.swift:14:24:14:31 | newValue | semmle.label | newValue | +| optional-chaining.swift:22:15:22:25 | storedValue [stored] | semmle.label | storedValue [stored] | +| optional-chaining.swift:23:15:23:25 | storedValue [stored] | semmle.label | storedValue [stored] | +| optional-chaining.swift:23:29:23:36 | newValue [stored] | semmle.label | newValue [stored] | +| optional-chaining.swift:29:5:29:8 | [post] ... ? [value] | semmle.label | [post] ... ? [value] | +| optional-chaining.swift:29:5:29:14 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:29:18:29:41 | source(...) | semmle.label | source(...) | +| optional-chaining.swift:30:10:30:12 | box [value] | semmle.label | box [value] | +| optional-chaining.swift:30:10:30:13 | ... ? [value] | semmle.label | ... ? [value] | +| optional-chaining.swift:30:10:30:19 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:31:10:31:12 | box [value] | semmle.label | box [value] | +| optional-chaining.swift:31:10:31:24 | ... .getValue(...) | semmle.label | ... .getValue(...) | +| optional-chaining.swift:37:5:37:13 | [post] container [optionalValue, stored] | semmle.label | [post] container [optionalValue, stored] | +| optional-chaining.swift:37:5:37:27 | [post] ... .optionalValue [stored] | semmle.label | [post] ... .optionalValue [stored] | +| optional-chaining.swift:37:5:37:37 | ... .computed | semmle.label | ... .computed | +| optional-chaining.swift:37:41:37:68 | source(...) | semmle.label | source(...) | +| optional-chaining.swift:38:10:38:18 | container [optionalValue, stored] | semmle.label | container [optionalValue, stored] | +| optional-chaining.swift:38:10:38:18 | container [storedValue, stored] | semmle.label | container [storedValue, stored] | +| optional-chaining.swift:38:10:38:32 | ... .optionalValue [stored] | semmle.label | ... .optionalValue [stored] | +| optional-chaining.swift:38:10:38:33 | ... ? [stored] | semmle.label | ... ? [stored] | +| optional-chaining.swift:38:10:38:40 | ... .stored | semmle.label | ... .stored | +| optional-chaining.swift:44:5:44:10 | [post] ... ? [next, value] | semmle.label | [post] ... ? [next, value] | +| optional-chaining.swift:44:5:44:15 | [post] ... .next [value] | semmle.label | [post] ... .next [value] | +| optional-chaining.swift:44:5:44:16 | [post] ... ? [value] | semmle.label | [post] ... ? [value] | +| optional-chaining.swift:44:5:44:22 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:44:26:44:49 | source(...) | semmle.label | source(...) | +| optional-chaining.swift:45:10:45:14 | outer [next, value] | semmle.label | outer [next, value] | +| optional-chaining.swift:45:10:45:15 | ... ? [next, value] | semmle.label | ... ? [next, value] | +| optional-chaining.swift:45:10:45:20 | ... .next [value] | semmle.label | ... .next [value] | +| optional-chaining.swift:45:10:45:21 | ... ? [value] | semmle.label | ... ? [value] | +| optional-chaining.swift:45:10:45:27 | ... .value | semmle.label | ... .value | +| optional-chaining.swift:49:9:49:14 | values [ArrayElement] | semmle.label | values [ArrayElement] | +| optional-chaining.swift:49:32:49:61 | ArrayLiteral [ArrayElement] | semmle.label | ArrayLiteral [ArrayElement] | +| optional-chaining.swift:49:33:49:60 | source(...) | semmle.label | source(...) | +| optional-chaining.swift:50:10:50:15 | values [ArrayElement] | semmle.label | values [ArrayElement] | +| optional-chaining.swift:50:10:50:19 | ... .subscript(...) | semmle.label | ... .subscript(...) | | short-return.swift:7:33:7:46 | source(...) | semmle.label | source(...) | | short-return.swift:8:10:8:19 | getValue(...) | semmle.label | getValue(...) | | subscripts.swift:14:39:14:52 | source(...) | semmle.label | source(...) | @@ -1756,6 +1799,7 @@ subpaths | capture.swift:49:13:49:13 | x | capture.swift:45:22:45:24 | arg | capture.swift:46:9:46:9 | y | capture.swift:50:10:50:10 | y | | capture.swift:60:13:60:13 | x | capture.swift:56:22:56:24 | arg | capture.swift:57:9:57:9 | [post] y [0] | capture.swift:61:10:61:10 | y [0] | | capture.swift:93:9:93:9 | x | capture.swift:99:16:99:16 | x | capture.swift:99:16:99:16 | x | capture.swift:94:13:94:19 | local(...) | +| capture.swift:215:18:215:21 | self [x] | capture.swift:220:29:220:29 | x | capture.swift:220:29:220:29 | x | capture.swift:215:18:215:29 | ... .getX(...) | | fields.swift:75:10:75:12 | sub [field] | fields.swift:66:15:66:19 | super [field] | fields.swift:66:15:66:25 | ... .field | fields.swift:75:10:75:18 | ... .field | | fields.swift:127:24:127:50 | source(...) | fields.swift:113:22:113:26 | value | fields.swift:116:16:116:18 | box [field] | fields.swift:127:13:127:51 | ... .withField(...) [field] | | fields.swift:129:24:129:52 | source(...) | fields.swift:113:22:113:26 | value | fields.swift:116:16:116:18 | box [field] | fields.swift:129:13:129:53 | ... .withField(...) [field] | @@ -1772,7 +1816,10 @@ subpaths | fields.swift:176:28:176:63 | source(...) | fields.swift:113:22:113:26 | value | fields.swift:116:16:116:18 | box [field] | fields.swift:176:17:176:64 | ... .withField(...) [field] | | flow-summaries.swift:54:35:54:48 | source(...) | flow-summaries.swift:54:53:54:53 | y | flow-summaries.swift:54:65:54:65 | y | flow-summaries.swift:54:10:54:67 | ... .throughCallback(...) | | flow-summaries.swift:55:35:55:48 | source(...) | flow-summaries.swift:55:53:55:53 | y | flow-summaries.swift:55:65:55:71 | ... + ... | flow-summaries.swift:55:10:55:73 | ... .throughCallback(...) | -| optional-chaining.swift:14:10:14:12 | box [value] | optional-chaining.swift:6:16:6:20 | value | optional-chaining.swift:6:16:6:20 | value | optional-chaining.swift:14:10:14:24 | ... .getValue(...) | +| optional-chaining.swift:31:10:31:12 | box [value] | optional-chaining.swift:6:16:6:20 | value | optional-chaining.swift:6:16:6:20 | value | optional-chaining.swift:31:10:31:24 | ... .getValue(...) | +| optional-chaining.swift:37:5:37:27 | [post] ... .optionalValue [stored] | optional-chaining.swift:23:29:23:36 | newValue [stored] | optional-chaining.swift:23:15:23:25 | storedValue [stored] | optional-chaining.swift:38:10:38:18 | container [storedValue, stored] | +| optional-chaining.swift:37:5:37:37 | ... .computed | optional-chaining.swift:14:24:14:31 | newValue | optional-chaining.swift:14:15:14:20 | stored | optional-chaining.swift:37:5:37:27 | [post] ... .optionalValue [stored] | +| optional-chaining.swift:38:10:38:18 | container [storedValue, stored] | optional-chaining.swift:22:15:22:25 | storedValue [stored] | optional-chaining.swift:22:15:22:25 | storedValue [stored] | optional-chaining.swift:38:10:38:32 | ... .optionalValue [stored] | | subscripts.swift:27:12:27:25 | source(...) | subscripts.swift:21:19:21:21 | key | subscripts.swift:22:19:22:21 | key | subscripts.swift:27:10:27:26 | ... .subscript(...) | | subscripts.swift:51:5:51:15 | ... .subscript(...) | subscripts.swift:47:27:47:34 | newValue | subscripts.swift:47:19:47:23 | field | subscripts.swift:52:10:52:10 | c [field] | | subscripts.swift:51:5:51:15 | ... .subscript(...) | subscripts.swift:47:27:47:34 | newValue | subscripts.swift:47:19:47:23 | field | subscripts.swift:53:10:53:10 | c [field] | @@ -1873,8 +1920,9 @@ testFailures | capture.swift:197:18:197:18 | x | capture.swift:194:13:194:25 | source(...) | capture.swift:197:18:197:18 | x | $@ | capture.swift:194:13:194:25 | source(...) | source(...) | | capture.swift:206:18:206:23 | ... .x | capture.swift:203:13:203:25 | source(...) | capture.swift:206:18:206:23 | ... .x | $@ | capture.swift:203:13:203:25 | source(...) | source(...) | | capture.swift:207:18:207:18 | x | capture.swift:203:13:203:25 | source(...) | capture.swift:207:18:207:18 | x | $@ | capture.swift:203:13:203:25 | source(...) | source(...) | -| capture.swift:215:18:215:23 | ... .x | capture.swift:213:13:213:25 | source(...) | capture.swift:215:18:215:23 | ... .x | $@ | capture.swift:213:13:213:25 | source(...) | source(...) | -| capture.swift:216:18:216:18 | x | capture.swift:213:13:213:25 | source(...) | capture.swift:216:18:216:18 | x | $@ | capture.swift:213:13:213:25 | source(...) | source(...) | +| capture.swift:215:18:215:35 | ... ?? ... | capture.swift:213:13:213:25 | source(...) | capture.swift:215:18:215:35 | ... ?? ... | $@ | capture.swift:213:13:213:25 | source(...) | source(...) | +| capture.swift:225:18:225:23 | ... .x | capture.swift:223:13:223:25 | source(...) | capture.swift:225:18:225:23 | ... .x | $@ | capture.swift:223:13:223:25 | source(...) | source(...) | +| capture.swift:226:18:226:18 | x | capture.swift:223:13:223:25 | source(...) | capture.swift:226:18:226:18 | x | $@ | capture.swift:223:13:223:25 | source(...) | source(...) | | enums.swift:16:14:16:14 | x | enums.swift:12:21:12:34 | source(...) | enums.swift:16:14:16:14 | x | $@ | enums.swift:12:21:12:34 | source(...) | source(...) | | enums.swift:27:14:27:14 | x | enums.swift:23:21:23:34 | source(...) | enums.swift:27:14:27:14 | x | $@ | enums.swift:23:21:23:34 | source(...) | source(...) | | enums.swift:36:10:36:10 | x | enums.swift:34:21:34:34 | source(...) | enums.swift:36:10:36:10 | x | $@ | enums.swift:34:21:34:34 | source(...) | source(...) | @@ -1945,10 +1993,11 @@ testFailures | modified-expressions.swift:10:10:10:17 | consumed | modified-expressions.swift:8:20:8:36 | source(...) | modified-expressions.swift:10:10:10:17 | consumed | $@ | modified-expressions.swift:8:20:8:36 | source(...) | source(...) | | modified-expressions.swift:16:10:16:15 | copied | modified-expressions.swift:14:20:14:33 | source(...) | modified-expressions.swift:16:10:16:15 | copied | $@ | modified-expressions.swift:14:20:14:33 | source(...) | source(...) | | modified-expressions.swift:22:10:22:18 | unchecked | modified-expressions.swift:20:20:20:35 | source(...) | modified-expressions.swift:22:10:22:18 | unchecked | $@ | modified-expressions.swift:20:20:20:35 | source(...) | source(...) | -| optional-chaining.swift:13:10:13:19 | ... .value | optional-chaining.swift:12:18:12:41 | source(...) | optional-chaining.swift:13:10:13:19 | ... .value | $@ | optional-chaining.swift:12:18:12:41 | source(...) | source(...) | -| optional-chaining.swift:14:10:14:24 | ... .getValue(...) | optional-chaining.swift:12:18:12:41 | source(...) | optional-chaining.swift:14:10:14:24 | ... .getValue(...) | $@ | optional-chaining.swift:12:18:12:41 | source(...) | source(...) | -| optional-chaining.swift:21:10:21:27 | ... .value | optional-chaining.swift:20:26:20:49 | source(...) | optional-chaining.swift:21:10:21:27 | ... .value | $@ | optional-chaining.swift:20:26:20:49 | source(...) | source(...) | -| optional-chaining.swift:26:10:26:19 | ... .subscript(...) | optional-chaining.swift:25:33:25:60 | source(...) | optional-chaining.swift:26:10:26:19 | ... .subscript(...) | $@ | optional-chaining.swift:25:33:25:60 | source(...) | source(...) | +| optional-chaining.swift:30:10:30:19 | ... .value | optional-chaining.swift:29:18:29:41 | source(...) | optional-chaining.swift:30:10:30:19 | ... .value | $@ | optional-chaining.swift:29:18:29:41 | source(...) | source(...) | +| optional-chaining.swift:31:10:31:24 | ... .getValue(...) | optional-chaining.swift:29:18:29:41 | source(...) | optional-chaining.swift:31:10:31:24 | ... .getValue(...) | $@ | optional-chaining.swift:29:18:29:41 | source(...) | source(...) | +| optional-chaining.swift:38:10:38:40 | ... .stored | optional-chaining.swift:37:41:37:68 | source(...) | optional-chaining.swift:38:10:38:40 | ... .stored | $@ | optional-chaining.swift:37:41:37:68 | source(...) | source(...) | +| optional-chaining.swift:45:10:45:27 | ... .value | optional-chaining.swift:44:26:44:49 | source(...) | optional-chaining.swift:45:10:45:27 | ... .value | $@ | optional-chaining.swift:44:26:44:49 | source(...) | source(...) | +| optional-chaining.swift:50:10:50:19 | ... .subscript(...) | optional-chaining.swift:49:33:49:60 | source(...) | optional-chaining.swift:50:10:50:19 | ... .subscript(...) | $@ | optional-chaining.swift:49:33:49:60 | source(...) | source(...) | | short-return.swift:8:10:8:19 | getValue(...) | short-return.swift:7:33:7:46 | source(...) | short-return.swift:8:10:8:19 | getValue(...) | $@ | short-return.swift:7:33:7:46 | source(...) | source(...) | | subscripts.swift:16:10:16:15 | ... .subscript(...) | subscripts.swift:14:39:14:52 | source(...) | subscripts.swift:16:10:16:15 | ... .subscript(...) | $@ | subscripts.swift:14:39:14:52 | source(...) | source(...) | | subscripts.swift:23:24:23:31 | newValue | subscripts.swift:28:17:28:30 | source(...) | subscripts.swift:23:24:23:31 | newValue | $@ | subscripts.swift:28:17:28:30 | source(...) | source(...) | diff --git a/unified/ql/test/library-tests/type-inference/optional-chaining.swift b/unified/ql/test/library-tests/type-inference/optional-chaining.swift index fb1947fd3e08..9f7c90a8c57a 100644 --- a/unified/ql/test/library-tests/type-inference/optional-chaining.swift +++ b/unified/ql/test/library-tests/type-inference/optional-chaining.swift @@ -22,3 +22,13 @@ func testOptionalChaining(_ box: OptionalChainBox?) { func testOptionalCall(_ callback: Optional<() -> String>) { let result = callback?() // $ type=result:String target=Function.callAsFunction } + +class WeakCaptureBox { + func getValue() -> String { return "" } + + func testWeakCapture() { + let closure = { [weak self] in // $ target=Optional.some + let value = self?.getValue() // $ type=value:String target=WeakCaptureBox.getValue + } + } +} diff --git a/unified/ql/test/library-tests/type-inference/type-inference.expected b/unified/ql/test/library-tests/type-inference/type-inference.expected index 0c1364a3d6dd..0a980e16d992 100644 --- a/unified/ql/test/library-tests/type-inference/type-inference.expected +++ b/unified/ql/test/library-tests/type-inference/type-inference.expected @@ -1095,6 +1095,10 @@ inferCertainType | optional-chaining.swift:23:16:23:23 | callback | Wrapped.Return | {EXTERNAL LOCATION} | String | | optional-chaining.swift:23:16:23:24 | ... ? | | {EXTERNAL LOCATION} | Function | | optional-chaining.swift:23:16:23:24 | ... ? | Return | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:30:9:30:15 | closure | | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:30:19:32:5 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:30:27:30:30 | Argument | | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:30:27:30:30 | self | | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | | overload_resolution.swift:4:17:4:17 | x | | {EXTERNAL LOCATION} | Int | | overload_resolution.swift:8:17:8:17 | x | | {EXTERNAL LOCATION} | Double | | overload_resolution.swift:12:17:12:17 | x | | {EXTERNAL LOCATION} | String | @@ -4865,6 +4869,24 @@ inferType | optional-chaining.swift:23:16:23:24 | ... ? | | {EXTERNAL LOCATION} | Function | | optional-chaining.swift:23:16:23:24 | ... ? | Return | {EXTERNAL LOCATION} | String | | optional-chaining.swift:23:16:23:26 | ...(...) | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:27:29:27:41 | Block | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:27:38:27:39 | "" | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:30:9:30:15 | closure | | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:30:19:32:5 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| optional-chaining.swift:30:22:30:21 | ... .some | | {EXTERNAL LOCATION} | Optional.some | +| optional-chaining.swift:30:22:30:21 | ... .some | (parent:some) | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:30:22:30:21 | ... .some | (parent:some).Wrapped | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:30:22:30:30 | ... .some(...) | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:30:22:30:30 | ... .some(...) | Wrapped | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:30:27:30:30 | Argument | | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:30:27:30:30 | self | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:30:27:30:30 | self | | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:30:27:30:30 | self | Wrapped | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:31:11:31:15 | value | | {EXTERNAL LOCATION} | String | +| optional-chaining.swift:31:19:31:22 | self | | {EXTERNAL LOCATION} | Optional | +| optional-chaining.swift:31:19:31:22 | self | Wrapped | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:31:19:31:23 | ... ? | | optional-chaining.swift:26:1:34:1 | WeakCaptureBox | +| optional-chaining.swift:31:19:31:34 | ... .getValue(...) | | {EXTERNAL LOCATION} | String | | overload_resolution.swift:4:17:4:17 | x | | {EXTERNAL LOCATION} | Int | | overload_resolution.swift:4:35:6:3 | Block | | {EXTERNAL LOCATION} | String | | overload_resolution.swift:5:12:5:16 | "int" | | {EXTERNAL LOCATION} | String | diff --git a/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected b/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected index f5ffb3494554..753d5f495454 100644 --- a/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected +++ b/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.expected @@ -84,5 +84,3 @@ nodes | CommandInjection.swift:163:41:163:74 | ... ! | semmle.label | ... ! | | CommandInjection.swift:163:53:163:72 | userControlledString | semmle.label | userControlledString | subpaths -testFailures -| CommandInjection.swift:131:2:131:21 | ... .executableURL | Fixed missing result: Alert | diff --git a/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.swift b/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.swift index e22691aad116..682eae7f5008 100644 --- a/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.swift +++ b/unified/ql/test/query-tests/security/CWE-078/CommandInjection/CommandInjection.swift @@ -128,7 +128,7 @@ func testCommandInjectionMore(mySafeString: String) { try! task4.run() let task5 = mkProcess() - task5?.executableURL = URL(fileURLWithPath: userControlledString) // $ MISSING: Alert + task5?.executableURL = URL(fileURLWithPath: userControlledString) // $ Alert task5?.arguments = [userControlledString] // $ MISSING: Alert try! task5?.run()