Skip to content

Commit 348c45d

Browse files
committed
Swift: Use enum content in URL and NSURL models.
1 parent 1c7d63a commit 348c45d

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/NsUrl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ private import codeql.swift.dataflow.ExternalFlow
1010
*/
1111
private class NsUrlSummaries extends SummaryModelCsv {
1212
override predicate row(string row) {
13-
row = ";NSURL;true;init(string:);(String);;Argument[0];ReturnValue;taint"
13+
row = ";NSURL;true;init(string:);(String);;Argument[0];ReturnValue.OptionalSome;taint"
1414
}
1515
}

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Url.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ private class UrlSummaries extends SummaryModelCsv {
8585
override predicate row(string row) {
8686
row =
8787
[
88-
";URL;true;init(string:);(String);;Argument[0];ReturnValue;taint",
89-
";URL;true;init(string:relativeTo:);(String,URL?);;Argument[0..1];ReturnValue;taint",
88+
";URL;true;init(string:);(String);;Argument[0];ReturnValue.OptionalSome;taint",
89+
";URL;true;init(string:relativeTo:);(String,URL?);;Argument[0..1];ReturnValue.OptionalSome;taint",
9090
";URL;true;init(fileURLWithPath:);;;Argument[0];ReturnValue;taint",
9191
";URL;true;init(fileURLWithPath:isDirectory:);;;Argument[0];ReturnValue;taint",
9292
";URL;true;init(fileURLWithPath:relativeTo:);;;Argument[0..1];ReturnValue;taint",
@@ -95,8 +95,8 @@ private class UrlSummaries extends SummaryModelCsv {
9595
";URL;true;init(fileURLWithFileSystemRepresentation:isDirectory:relativeTo:);;;Argument[0];ReturnValue;taint",
9696
";URL;true;init(fileURLWithFileSystemRepresentation:isDirectory:relativeTo:);;;Argument[2];ReturnValue;taint",
9797
";URL;true;init(fileReferenceLiteralResourceName:);;;Argument[0];ReturnValue;taint",
98-
";URL;true;init(_:);;;Argument[0];ReturnValue;taint",
99-
";URL;true;init(_:isDirectory:);;;Argument[0];ReturnValue;taint",
98+
";URL;true;init(_:);;;Argument[0];ReturnValue.OptionalSome;taint",
99+
";URL;true;init(_:isDirectory:);;;Argument[0];ReturnValue.OptionalSome;taint",
100100
";URL;true;init(resolvingBookmarkData:options:relativeTo:bookmarkDataIsStale:);;;Argument[0];ReturnValue;taint",
101101
";URL;true;init(resolvingBookmarkData:options:relativeTo:bookmarkDataIsStale:);;;Argument[2];ReturnValue;taint",
102102
";URL;true;init(resolvingAliasFileAt:options:);;;Argument[0];ReturnValue;taint",

swift/ql/test/query-tests/Security/CWE-078/CommandInjection.expected

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ edges
3131
| CommandInjection.swift:79:40:79:94 | call to String.init(contentsOf:) | CommandInjection.swift:79:40:79:94 | call to String.init(contentsOf:) [some:0] |
3232
| CommandInjection.swift:79:40:79:94 | call to String.init(contentsOf:) [some:0] | CommandInjection.swift:79:8:79:12 | let ...? [some:0] |
3333
| CommandInjection.swift:94:2:94:2 | [post] task3 [executableURL] | CommandInjection.swift:94:2:94:2 | [post] task3 |
34-
| CommandInjection.swift:94:24:94:56 | call to URL.init(string:) | CommandInjection.swift:94:24:94:56 | call to URL.init(string:) [some:0] |
35-
| CommandInjection.swift:94:24:94:56 | call to URL.init(string:) | CommandInjection.swift:94:24:94:57 | ...! |
3634
| CommandInjection.swift:94:24:94:56 | call to URL.init(string:) [some:0] | CommandInjection.swift:94:24:94:57 | ...! |
3735
| CommandInjection.swift:94:24:94:57 | ...! | CommandInjection.swift:94:2:94:2 | [post] task3 [executableURL] |
38-
| CommandInjection.swift:94:36:94:36 | userControlledString | CommandInjection.swift:94:24:94:56 | call to URL.init(string:) |
36+
| CommandInjection.swift:94:36:94:36 | userControlledString | CommandInjection.swift:94:24:94:56 | call to URL.init(string:) [some:0] |
3937
| CommandInjection.swift:95:2:95:2 | [post] task3 [arguments] | CommandInjection.swift:95:2:95:2 | [post] task3 |
4038
| CommandInjection.swift:95:20:95:48 | [...] | CommandInjection.swift:95:2:95:2 | [post] task3 [arguments] |
4139
| CommandInjection.swift:95:28:95:28 | userControlledString | CommandInjection.swift:95:20:95:48 | [...] |
@@ -62,10 +60,8 @@ edges
6260
| CommandInjection.swift:123:75:123:75 | userControlledString | CommandInjection.swift:123:67:123:95 | [...] |
6361
| CommandInjection.swift:123:75:123:75 | userControlledString | CommandInjection.swift:126:35:126:35 | userControlledString |
6462
| CommandInjection.swift:123:75:123:75 | userControlledString | CommandInjection.swift:127:70:127:70 | userControlledString |
65-
| CommandInjection.swift:126:23:126:55 | call to URL.init(string:) | CommandInjection.swift:126:23:126:55 | call to URL.init(string:) [some:0] |
66-
| CommandInjection.swift:126:23:126:55 | call to URL.init(string:) | CommandInjection.swift:126:23:126:56 | ...! |
6763
| CommandInjection.swift:126:23:126:55 | call to URL.init(string:) [some:0] | CommandInjection.swift:126:23:126:56 | ...! |
68-
| CommandInjection.swift:126:35:126:35 | userControlledString | CommandInjection.swift:126:23:126:55 | call to URL.init(string:) |
64+
| CommandInjection.swift:126:35:126:35 | userControlledString | CommandInjection.swift:126:23:126:55 | call to URL.init(string:) [some:0] |
6965
| CommandInjection.swift:127:70:127:70 | userControlledString | CommandInjection.swift:127:62:127:90 | [...] |
7066
nodes
7167
| CommandInjection.swift:38:22:38:33 | command | semmle.label | command |
@@ -100,7 +96,6 @@ nodes
10096
| CommandInjection.swift:79:40:79:94 | call to String.init(contentsOf:) [some:0] | semmle.label | call to String.init(contentsOf:) [some:0] |
10197
| CommandInjection.swift:94:2:94:2 | [post] task3 | semmle.label | [post] task3 |
10298
| CommandInjection.swift:94:2:94:2 | [post] task3 [executableURL] | semmle.label | [post] task3 [executableURL] |
103-
| CommandInjection.swift:94:24:94:56 | call to URL.init(string:) | semmle.label | call to URL.init(string:) |
10499
| CommandInjection.swift:94:24:94:56 | call to URL.init(string:) [some:0] | semmle.label | call to URL.init(string:) [some:0] |
105100
| CommandInjection.swift:94:24:94:57 | ...! | semmle.label | ...! |
106101
| CommandInjection.swift:94:36:94:36 | userControlledString | semmle.label | userControlledString |
@@ -129,7 +124,6 @@ nodes
129124
| CommandInjection.swift:122:42:122:42 | userControlledString | semmle.label | userControlledString |
130125
| CommandInjection.swift:123:67:123:95 | [...] | semmle.label | [...] |
131126
| CommandInjection.swift:123:75:123:75 | userControlledString | semmle.label | userControlledString |
132-
| CommandInjection.swift:126:23:126:55 | call to URL.init(string:) | semmle.label | call to URL.init(string:) |
133127
| CommandInjection.swift:126:23:126:55 | call to URL.init(string:) [some:0] | semmle.label | call to URL.init(string:) [some:0] |
134128
| CommandInjection.swift:126:23:126:56 | ...! | semmle.label | ...! |
135129
| CommandInjection.swift:126:35:126:35 | userControlledString | semmle.label | userControlledString |

0 commit comments

Comments
 (0)