Skip to content

Commit 2c52020

Browse files
committed
Swift: Add sinks.
1 parent 8573b30 commit 2c52020

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ private class PathInjectionSinks extends SinkModelCsv {
130130
";Realm.Configuration;true;init(fileURL:inMemoryIdentifier:syncConfiguration:encryptionKey:readOnly:schemaVersion:migrationBlock:deleteRealmIfMigrationNeeded:shouldCompactOnLaunch:objectTypes:seedFilePath:);;;Argument[10];path-injection",
131131
";Realm.Configuration;true;fileURL;;;PostUpdate;path-injection",
132132
";Realm.Configuration;true;seedFilePath;;;PostUpdate;path-injection",
133+
// sqlite3
134+
";;false;sqlite3_open(_:_:);;;Argument[0];path-injection",
135+
";;false;sqlite3_open16(_:_:);;;Argument[0];path-injection",
136+
";;false;sqlite3_open_v2(_:_:_:_:);;;Argument[0];path-injection",
137+
";;false;sqlite3_database_file_object(_:);;;Argument[0];path-injection",
138+
";;false;sqlite3_filename_database(_:);;;Argument[0];path-injection",
139+
";;false;sqlite3_filename_journal(_:);;;Argument[0];path-injection",
140+
";;false;sqlite3_filename_wal(_:);;;Argument[0];path-injection",
141+
";;false;sqlite3_free_filename(_:);;;Argument[0];path-injection",
142+
";;false;sqlite3_temp_directory;;;PostUpdate;path-injection",
143+
// SQLite.swift
144+
";Connection.Location.uri;true;init(_:parameters:);;;Argument[0];path-injection",
145+
";Connection;true;init(_:readonly:);;;Argument[0];path-injection",
133146
]
134147
}
135148
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,11 @@ func test(buffer1: UnsafeMutablePointer<UInt8>, buffer2: UnsafeMutablePointer<UI
375375
remoteData.copyBytes(to: buffer2, count: remoteData.count)
376376

377377
_ = sqlite3_open("myFile.sqlite3", &db) // GOOD
378-
_ = sqlite3_open(remoteString, &db) // $ MISSING: hasPathInjection=253
378+
_ = sqlite3_open(remoteString, &db) // $ hasPathInjection=253
379379
_ = sqlite3_open16(buffer1, &db) // GOOD
380-
_ = sqlite3_open16(buffer2, &db) // $ MISSING: hasPathInjection=253
380+
_ = sqlite3_open16(buffer2, &db) // $ hasPathInjection=373
381381
_ = sqlite3_open_v2("myFile.sqlite3", &db, 0, nil) // GOOD
382-
_ = sqlite3_open_v2(remoteString, &db, 0, nil) // $ MISSING: hasPathInjection=253
382+
_ = sqlite3_open_v2(remoteString, &db, 0, nil) // $ hasPathInjection=253
383383

384384
sqlite3_temp_directory = UnsafeMutablePointer<CChar>(mutating: NSString(string: "myFile.sqlite3").utf8String) // GOOD
385385
sqlite3_temp_directory = UnsafeMutablePointer<CChar>(mutating: NSString(string: remoteString).utf8String) // $ MISSING: hasPathInjection=253
@@ -390,7 +390,7 @@ func test(buffer1: UnsafeMutablePointer<UInt8>, buffer2: UnsafeMutablePointer<UI
390390
try! _ = Connection(Connection.Location.uri("myFile.sqlite3")) // GOOD
391391
try! _ = Connection(Connection.Location.uri(remoteString)) // $ MISSING: hasPathInjection=253
392392
try! _ = Connection("myFile.sqlite3") // GOOD
393-
try! _ = Connection(remoteString) // $ MISSING: hasPathInjection=253
393+
try! _ = Connection(remoteString) // $ hasPathInjection=253
394394
}
395395

396396
func testBarriers() {

0 commit comments

Comments
 (0)