Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ private DataFlow::Node getSinkFromCall(CallExpr call, AccessPathToken token) {
arg.getName() + ":" = token.getAnArgument()
)
or
token = "Argument[self]" and
token.getName() = "Argument" and
token.getAnArgument() = "self" and
result.isReceiverArgument(call)
}

Expand Down Expand Up @@ -263,7 +264,8 @@ private DataFlow::Node getSourceFromCallable(Callable callable, AccessPathToken
param.getExternalName() + ":" = token.getAnArgument()
)
or
token = "Parameter[self]" and
token.getName() = "Parameter" and
token.getAnArgument() = "self" and
result.isReceiverParameter(callable)
}

Expand Down
4 changes: 4 additions & 0 deletions unified/ql/test/library-tests/mad/test.expected
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ isSink
| test.swift:101:18:101:24 | fileURL | path-injection |
| test.swift:107:23:107:34 | seedFilePath | path-injection |
| test.swift:119:29:119:34 | string | path-injection |
| test.swift:137:5:139:5 | [self arg] ... .sinkArgs(...) | shorthand-sink |
| test.swift:138:9:138:14 | string | shorthand-sink |
isSource
| test.swift:4:5:4:27 | String(...) | remote |
| test.swift:5:5:5:44 | String(...) | remote |
Expand All @@ -25,3 +27,5 @@ isSource
| test.swift:10:5:12:24 | String(...) | local |
| test.swift:13:5:15:28 | String(...) | local |
| test.swift:29:29:29:32 | text | local |
| test.swift:129:5:133:5 | [self param] func ShorthandTestSub.sourceParams | shorthand-source |
| test.swift:130:11:130:11 | x | shorthand-source |
11 changes: 11 additions & 0 deletions unified/ql/test/library-tests/mad/test.ext.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extensions:
- addsTo:
pack: codeql/unified-all
extensible: legacySourceModel
data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance
- ["", "ShorthandTest", true, "sourceParams(_:)", "", "", "Parameter[self,0]", "shorthand-source", "manual"]
- addsTo:
pack: codeql/unified-all
extensible: legacySinkModel
data: # namespace, type, subtypes, name, signature, ext, input, kind, provenance
- ["", "ShorthandTest", true, "sinkArgs(_:)", "", "", "Argument[self,0]", "shorthand-sink", "manual"]
20 changes: 20 additions & 0 deletions unified/ql/test/library-tests/mad/test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,23 @@ class Connection {
func testConnectionLocation(string: String) {
Connection.Location.uri(string, parameters: "") // $ isSink=path-injection
}

class ShorthandTest {
func sourceParams(_ x: String) {}

func sinkArgs(_ x: String) {}
}

class ShorthandTestSub: ShorthandTest {
override func sourceParams(
_ x: String // $ isSource=shorthand-source
) {
_ = self
} // $ isSource=shorthand-source
}

func testShorthandTokens(obj: ShorthandTest, string: String) {
obj.sinkArgs(
string // $ isSink=shorthand-sink
) // $ isSink=shorthand-sink
}
Loading