Skip to content

Commit 350cd9b

Browse files
authored
Merge pull request #22956 from asgerf/unified/fix-atomic-token-check
Unified: Use getAnArgument() to check argument of a MaD token
2 parents e68cb84 + 75373ee commit 350cd9b

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ private DataFlow::Node getSinkFromCall(CallExpr call, AccessPathToken token) {
224224
arg.getName() + ":" = token.getAnArgument()
225225
)
226226
or
227-
token = "Argument[self]" and
227+
token.getName() = "Argument" and
228+
token.getAnArgument() = "self" and
228229
result.isReceiverArgument(call)
229230
}
230231

@@ -263,7 +264,8 @@ private DataFlow::Node getSourceFromCallable(Callable callable, AccessPathToken
263264
param.getExternalName() + ":" = token.getAnArgument()
264265
)
265266
or
266-
token = "Parameter[self]" and
267+
token.getName() = "Parameter" and
268+
token.getAnArgument() = "self" and
267269
result.isReceiverParameter(callable)
268270
}
269271

‎unified/ql/test/library-tests/mad/test.expected‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ isSink
1616
| test.swift:101:18:101:24 | fileURL | path-injection |
1717
| test.swift:107:23:107:34 | seedFilePath | path-injection |
1818
| test.swift:119:29:119:34 | string | path-injection |
19+
| test.swift:137:5:139:5 | [self arg] ... .sinkArgs(...) | shorthand-sink |
20+
| test.swift:138:9:138:14 | string | shorthand-sink |
1921
isSource
2022
| test.swift:4:5:4:27 | String(...) | remote |
2123
| test.swift:5:5:5:44 | String(...) | remote |
@@ -25,3 +27,5 @@ isSource
2527
| test.swift:10:5:12:24 | String(...) | local |
2628
| test.swift:13:5:15:28 | String(...) | local |
2729
| test.swift:29:29:29:32 | text | local |
30+
| test.swift:129:5:133:5 | [self param] func ShorthandTestSub.sourceParams | shorthand-source |
31+
| test.swift:130:11:130:11 | x | shorthand-source |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/unified-all
4+
extensible: legacySourceModel
5+
data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance
6+
- ["", "ShorthandTest", true, "sourceParams(_:)", "", "", "Parameter[self,0]", "shorthand-source", "manual"]
7+
- addsTo:
8+
pack: codeql/unified-all
9+
extensible: legacySinkModel
10+
data: # namespace, type, subtypes, name, signature, ext, input, kind, provenance
11+
- ["", "ShorthandTest", true, "sinkArgs(_:)", "", "", "Argument[self,0]", "shorthand-sink", "manual"]

‎unified/ql/test/library-tests/mad/test.swift‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,23 @@ class Connection {
118118
func testConnectionLocation(string: String) {
119119
Connection.Location.uri(string, parameters: "") // $ isSink=path-injection
120120
}
121+
122+
class ShorthandTest {
123+
func sourceParams(_ x: String) {}
124+
125+
func sinkArgs(_ x: String) {}
126+
}
127+
128+
class ShorthandTestSub: ShorthandTest {
129+
override func sourceParams(
130+
_ x: String // $ isSource=shorthand-source
131+
) {
132+
_ = self
133+
} // $ isSource=shorthand-source
134+
}
135+
136+
func testShorthandTokens(obj: ShorthandTest, string: String) {
137+
obj.sinkArgs(
138+
string // $ isSink=shorthand-sink
139+
) // $ isSink=shorthand-sink
140+
}

0 commit comments

Comments
 (0)