Skip to content

Commit 0525e9c

Browse files
authored
Merge pull request #17128 from geoffw0/swiftcmdline
Swift: Disable some FileManager models
2 parents b87d832 + 8e68e0d commit 0525e9c

File tree

6 files changed

+392
-364
lines changed

6 files changed

+392
-364
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The model for `FileManager` no longer considers methods that return paths on the file system as taint sources. This is because these sources have been found to produce results of low value.

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ private import codeql.swift.dataflow.ExternalFlow
77

88
/**
99
* A model for `FileManager` members that are flow sources.
10+
*
11+
* Note that functions returning paths on the file system have been removed
12+
* from this model. Though they are in principle tainted by the data on the
13+
* local filesystem, in practice we've found results from them almost always
14+
* have little value.
1015
*/
1116
private class FileManagerSource extends SourceModelCsv {
1217
override predicate row(string row) {
1318
row =
1419
[
15-
";FileManager;true;contentsOfDirectory(at:includingPropertiesForKeys:options:);;;ReturnValue;local",
16-
";FileManager;true;contentsOfDirectory(atPath:);;;ReturnValue;local",
17-
";FileManager;true;directoryContents(atPath:);;;ReturnValue;local",
18-
";FileManager;true;subpathsOfDirectory(atPath:);;;ReturnValue;local",
19-
";FileManager;true;subpaths(atPath:);;;ReturnValue;local",
20-
";FileManager;true;destinationOfSymbolicLink(atPath:);;;ReturnValue;local",
21-
";FileManager;true;pathContentOfSymbolicLink(atPath:);;;ReturnValue;local",
20+
//";FileManager;true;contentsOfDirectory(at:includingPropertiesForKeys:options:);;;ReturnValue;local",
21+
//";FileManager;true;contentsOfDirectory(atPath:);;;ReturnValue;local",
22+
//";FileManager;true;directoryContents(atPath:);;;ReturnValue;local",
23+
//";FileManager;true;subpathsOfDirectory(atPath:);;;ReturnValue;local",
24+
//";FileManager;true;subpaths(atPath:);;;ReturnValue;local",
25+
//";FileManager;true;destinationOfSymbolicLink(atPath:);;;ReturnValue;local",
26+
//";FileManager;true;pathContentOfSymbolicLink(atPath:);;;ReturnValue;local",
2227
";FileManager;true;contents(atPath:);;;ReturnValue;local"
2328
]
2429
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
failures
21
testFailures
2+
failures

swift/ql/test/library-tests/dataflow/flowsources/filemanager.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class FileManager : NSObject {
3434
func testFileHandle(fm: FileManager, url: URL, path: String) {
3535
do
3636
{
37-
let contents1 = try fm.contentsOfDirectory(at: url, includingPropertiesForKeys: nil) // $ source=local
38-
let contents2 = try fm.contentsOfDirectory(atPath: path) // $ source=local
39-
let contents3 = fm.directoryContents(atPath: path)! // $ source=local
37+
let contents1 = try fm.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
38+
let contents2 = try fm.contentsOfDirectory(atPath: path)
39+
let contents3 = fm.directoryContents(atPath: path)!
4040

41-
let subpaths1 = try fm.subpathsOfDirectory(atPath: path) // $ source=local
42-
let subpaths2 = fm.subpaths(atPath: path)! // $ source=local
41+
let subpaths1 = try fm.subpathsOfDirectory(atPath: path)
42+
let subpaths2 = fm.subpaths(atPath: path)!
4343

44-
let link1 = try fm.destinationOfSymbolicLink(atPath: path) // $ source=local
45-
let link2 = fm.pathContentOfSymbolicLink(atPath: path)! // $ source=local
44+
let link1 = try fm.destinationOfSymbolicLink(atPath: path)
45+
let link2 = fm.pathContentOfSymbolicLink(atPath: path)!
4646

4747
let data = fm.contents(atPath: path)! // $ source=local
4848
} catch {

0 commit comments

Comments
 (0)