Skip to content

Commit 842f2c4

Browse files
geoffw0Copilot
andcommitted
unified: Cover modeled variadic formatting and direct C string arguments
Add positive and safe comparisons for localized formatting, NSLog and imported C format functions without closure-based conversion. All ten prior results are preserved and eight additional sink locations are covered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 912efca commit 842f2c4

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎unified/ql/test/query-tests/security/CWE-134/UncontrolledFormatString/UncontrolledFormatString.expected‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
| UncontrolledFormatString.swift:118:61:118:67 | tainted | UncontrolledFormatString.swift:91:24:91:77 | String(...) | UncontrolledFormatString.swift:118:61:118:67 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:91:24:91:77 | String(...) | this user-provided value |
1010
| UncontrolledFormatString.swift:130:39:130:45 | tainted | UncontrolledFormatString.swift:91:24:91:77 | String(...) | UncontrolledFormatString.swift:130:39:130:45 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:91:24:91:77 | String(...) | this user-provided value |
1111
| UncontrolledFormatString.swift:135:20:135:44 | NSString(...) | UncontrolledFormatString.swift:91:24:91:77 | String(...) | UncontrolledFormatString.swift:135:20:135:44 | NSString(...) | This format string depends on $@. | UncontrolledFormatString.swift:91:24:91:77 | String(...) | this user-provided value |
12+
| UncontrolledFormatString.swift:163:42:163:48 | tainted | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:163:42:163:48 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
13+
| UncontrolledFormatString.swift:165:40:165:64 | NSString(...) | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:165:40:165:64 | NSString(...) | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
14+
| UncontrolledFormatString.swift:167:47:167:71 | NSString(...) | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:167:47:167:71 | NSString(...) | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
15+
| UncontrolledFormatString.swift:170:11:170:17 | tainted | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:170:11:170:17 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
16+
| UncontrolledFormatString.swift:173:20:173:26 | tainted | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:173:20:173:26 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
17+
| UncontrolledFormatString.swift:175:17:175:23 | tainted | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:175:17:175:23 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
18+
| UncontrolledFormatString.swift:177:23:177:29 | tainted | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:177:23:177:29 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
19+
| UncontrolledFormatString.swift:179:31:179:37 | tainted | UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:179:31:179:37 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:161:24:161:77 | String(...) | this user-provided value |
1220
edges
1321
| UncontrolledFormatString.swift:77:14:77:19 | format | UncontrolledFormatString.swift:78:22:80:5 | FunctionExpr [format] | provenance | |
1422
| UncontrolledFormatString.swift:78:22:80:5 | FunctionExpr [format] | UncontrolledFormatString.swift:79:16:79:21 | format | provenance | |
@@ -27,6 +35,17 @@ edges
2735
| UncontrolledFormatString.swift:111:50:111:56 | tainted | UncontrolledFormatString.swift:111:33:111:57 | NSString(...) | provenance | |
2836
| UncontrolledFormatString.swift:116:11:116:17 | tainted | UncontrolledFormatString.swift:77:14:77:19 | format | provenance | |
2937
| UncontrolledFormatString.swift:135:37:135:43 | tainted | UncontrolledFormatString.swift:135:20:135:44 | NSString(...) | provenance | |
38+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:163:42:163:48 | tainted | provenance | |
39+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:165:57:165:63 | tainted | provenance | |
40+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:167:64:167:70 | tainted | provenance | |
41+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:170:11:170:17 | tainted | provenance | |
42+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:173:20:173:26 | tainted | provenance | |
43+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:175:17:175:23 | tainted | provenance | |
44+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:177:23:177:29 | tainted | provenance | |
45+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | UncontrolledFormatString.swift:179:31:179:37 | tainted | provenance | |
46+
| UncontrolledFormatString.swift:161:24:161:77 | String(...) | UncontrolledFormatString.swift:161:9:161:15 | tainted | provenance | |
47+
| UncontrolledFormatString.swift:165:57:165:63 | tainted | UncontrolledFormatString.swift:165:40:165:64 | NSString(...) | provenance | |
48+
| UncontrolledFormatString.swift:167:64:167:70 | tainted | UncontrolledFormatString.swift:167:47:167:71 | NSString(...) | provenance | |
3049
nodes
3150
| UncontrolledFormatString.swift:77:14:77:19 | format | semmle.label | format |
3251
| UncontrolledFormatString.swift:78:22:80:5 | FunctionExpr [format] | semmle.label | FunctionExpr [format] |
@@ -46,4 +65,16 @@ nodes
4665
| UncontrolledFormatString.swift:130:39:130:45 | tainted | semmle.label | tainted |
4766
| UncontrolledFormatString.swift:135:20:135:44 | NSString(...) | semmle.label | NSString(...) |
4867
| UncontrolledFormatString.swift:135:37:135:43 | tainted | semmle.label | tainted |
68+
| UncontrolledFormatString.swift:161:9:161:15 | tainted | semmle.label | tainted |
69+
| UncontrolledFormatString.swift:161:24:161:77 | String(...) | semmle.label | String(...) |
70+
| UncontrolledFormatString.swift:163:42:163:48 | tainted | semmle.label | tainted |
71+
| UncontrolledFormatString.swift:165:40:165:64 | NSString(...) | semmle.label | NSString(...) |
72+
| UncontrolledFormatString.swift:165:57:165:63 | tainted | semmle.label | tainted |
73+
| UncontrolledFormatString.swift:167:47:167:71 | NSString(...) | semmle.label | NSString(...) |
74+
| UncontrolledFormatString.swift:167:64:167:70 | tainted | semmle.label | tainted |
75+
| UncontrolledFormatString.swift:170:11:170:17 | tainted | semmle.label | tainted |
76+
| UncontrolledFormatString.swift:173:20:173:26 | tainted | semmle.label | tainted |
77+
| UncontrolledFormatString.swift:175:17:175:23 | tainted | semmle.label | tainted |
78+
| UncontrolledFormatString.swift:177:23:177:29 | tainted | semmle.label | tainted |
79+
| UncontrolledFormatString.swift:179:31:179:37 | tainted | semmle.label | tainted |
4980
subpaths

‎unified/ql/test/query-tests/security/CWE-134/UncontrolledFormatString/UncontrolledFormatString.swift‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,26 @@ func tests() throws {
156156
_ = MyString(formatString: tainted, "abc") // $ MISSING: Alert
157157
_ = MyString(formatString: "%s", tainted) // GOOD: format not tainted
158158
}
159+
160+
func testModeledFormatStrings() throws {
161+
let tainted = try! String(contentsOf: URL(string: "http://example.com")!) // $ Source
162+
163+
_ = String.localizedStringWithFormat(tainted, "abc") // $ Alert
164+
_ = String.localizedStringWithFormat("%@", tainted) // GOOD: format not tainted
165+
NSString.localizedStringWithFormat(NSString(string: tainted), "abc") // $ Alert
166+
NSString.localizedStringWithFormat(NSString(string: "%@"), tainted) // GOOD: format not tainted
167+
NSMutableString.localizedStringWithFormat(NSString(string: tainted), "abc") // $ Alert
168+
NSMutableString.localizedStringWithFormat(NSString(string: "%@"), tainted) // GOOD: format not tainted
169+
170+
NSLog(tainted, "abc") // $ Alert
171+
NSLog("%@", tainted) // GOOD: format not tainted
172+
173+
_ = dprintf(0, tainted, "abc") // $ Alert
174+
_ = dprintf(0, "%s", tainted) // GOOD: format not tainted
175+
_ = vprintf(tainted, getVaList([])) // $ Alert
176+
_ = vprintf("%s", getVaList([tainted])) // GOOD: format not tainted
177+
_ = vfprintf(nil, tainted, getVaList([])) // $ Alert
178+
_ = vfprintf(nil, "%s", getVaList([tainted])) // GOOD: format not tainted
179+
_ = vasprintf_l(nil, nil, tainted, getVaList([])) // $ Alert
180+
_ = vasprintf_l(nil, nil, "%s", getVaList([tainted])) // GOOD: format not tainted
181+
}

0 commit comments

Comments
 (0)