Skip to content

Commit ebb379f

Browse files
committed
Swift: Fix sqlite3_temp_directory sink.
1 parent 0973fb3 commit ebb379f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

swift/ql/lib/codeql/swift/security/PathInjectionExtensions.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ private class DefaultPathInjectionSink extends PathInjectionSink {
3333
DefaultPathInjectionSink() { sinkNode(this, "path-injection") }
3434
}
3535

36+
/**
37+
* A sink that is a write to a global variable.
38+
*/
39+
private class GlobalVariablePathInjectionSink extends PathInjectionSink {
40+
GlobalVariablePathInjectionSink() {
41+
// value assigned to global variable `sqlite3_temp_directory`
42+
// the sink should be the `DeclRefExpr` itself, but we don't currently have taint flow to globals.
43+
exists(AssignExpr ae |
44+
ae.getDest().(DeclRefExpr).getDecl().(VarDecl).getName() = "sqlite3_temp_directory" and
45+
ae.getSource() = this.asExpr()
46+
)
47+
}
48+
}
49+
3650
private class DefaultPathInjectionBarrier extends PathInjectionBarrier {
3751
DefaultPathInjectionBarrier() {
3852
// This is a simplified implementation.
@@ -139,7 +153,6 @@ private class PathInjectionSinks extends SinkModelCsv {
139153
";;false;sqlite3_filename_journal(_:);;;Argument[0];path-injection",
140154
";;false;sqlite3_filename_wal(_:);;;Argument[0];path-injection",
141155
";;false;sqlite3_free_filename(_:);;;Argument[0];path-injection",
142-
";;false;sqlite3_temp_directory;;;PostUpdate;path-injection",
143156
// SQLite.swift
144157
";Connection.Location.uri;true;init(_:parameters:);;;Argument[0];path-injection",
145158
";Connection;true;init(_:readonly:);;;Argument[0];path-injection",

swift/ql/test/query-tests/Security/CWE-022/testPathInjection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func test(buffer1: UnsafeMutablePointer<UInt8>, buffer2: UnsafeMutablePointer<UI
382382
_ = sqlite3_open_v2(remoteString, &db, 0, nil) // $ hasPathInjection=253
383383

384384
sqlite3_temp_directory = UnsafeMutablePointer<CChar>(mutating: NSString(string: "myFile.sqlite3").utf8String) // GOOD
385-
sqlite3_temp_directory = UnsafeMutablePointer<CChar>(mutating: NSString(string: remoteString).utf8String) // $ MISSING: hasPathInjection=253
385+
sqlite3_temp_directory = UnsafeMutablePointer<CChar>(mutating: NSString(string: remoteString).utf8String) // $ hasPathInjection=253
386386

387387
// SQLite.swift
388388

0 commit comments

Comments
 (0)