@@ -61,6 +61,41 @@ private class EnumConstructorPathInjectionSink extends PathInjectionSink {
61
61
}
62
62
}
63
63
64
+ /**
65
+ * A string that might be a label for a path argument.
66
+ */
67
+ pragma [ inline]
68
+ private predicate pathLikeHeuristic ( string label ) {
69
+ label =
70
+ [
71
+ "atFile" , "atPath" , "atDirectory" , "toFile" , "toPath" , "toDirectory" , "inFile" , "inPath" ,
72
+ "inDirectory" , "contentsOfFile" , "contentsOfPath" , "contentsOfDirectory" , "filePath" ,
73
+ "directory" , "directoryPath"
74
+ ]
75
+ }
76
+
77
+ /**
78
+ * A path injection sink that is determined by imprecise methods.
79
+ */
80
+ private class HeuristicPathInjectionSink extends PathInjectionSink {
81
+ HeuristicPathInjectionSink ( ) {
82
+ // by parameter name
83
+ exists ( CallExpr ce , int ix , ParamDecl pd |
84
+ pathLikeHeuristic ( pragma [ only_bind_into ] ( pd .getName ( ) ) ) and
85
+ pd .getType ( ) .getUnderlyingType ( ) .getName ( ) = [ "String" , "NSString" ] and
86
+ pd = ce .getStaticTarget ( ) .getParam ( ix ) and
87
+ this .asExpr ( ) = ce .getArgument ( ix ) .getExpr ( )
88
+ )
89
+ or
90
+ // by argument name
91
+ exists ( Argument a |
92
+ pathLikeHeuristic ( pragma [ only_bind_into ] ( a .getLabel ( ) ) ) and
93
+ a .getExpr ( ) .getType ( ) .getUnderlyingType ( ) .getName ( ) = [ "String" , "NSString" ] and
94
+ this .asExpr ( ) = a .getExpr ( )
95
+ )
96
+ }
97
+ }
98
+
64
99
private class DefaultPathInjectionBarrier extends PathInjectionBarrier {
65
100
DefaultPathInjectionBarrier ( ) {
66
101
// This is a simplified implementation.
@@ -87,7 +122,14 @@ private class PathInjectionSinks extends SinkModelCsv {
87
122
override predicate row ( string row ) {
88
123
row =
89
124
[
125
+ ";Data;true;init(contentsOf:options:);;;Argument[0];path-injection" ,
90
126
";Data;true;write(to:options:);;;Argument[0];path-injection" ,
127
+ ";NSData;true;init(contentsOfFile:);;;Argument[0];path-injection" ,
128
+ ";NSData;true;init(contentsOfFile:options:);;;Argument[0];path-injection" ,
129
+ ";NSData;true;init(contentsOf:);;;Argument[0];path-injection" ,
130
+ ";NSData;true;init(contentsOf:options:);;;Argument[0];path-injection" ,
131
+ ";NSData;true;init(contentsOfMappedFile:);;;Argument[0];path-injection" ,
132
+ ";NSData;true;dataWithContentsOfMappedFile(_:);;;Argument[0];path-injection" ,
91
133
";NSData;true;write(to:atomically:);;;Argument[0];path-injection" ,
92
134
";NSData;true;write(to:options:);;;Argument[0];path-injection" ,
93
135
";NSData;true;write(toFile:atomically:);;;Argument[0];path-injection" ,
@@ -118,12 +160,14 @@ private class PathInjectionSinks extends SinkModelCsv {
118
160
";FileManager;true;fileExists(atPath:);;;Argument[0];path-injection" ,
119
161
";FileManager;true;fileExists(atPath:isDirectory:);;;Argument[0];path-injection" ,
120
162
";FileManager;true;setAttributes(_:ofItemAtPath:);;;Argument[1];path-injection" ,
163
+ ";FileManager;true;attributesOfItem(atPath:);;;Argument[0];path-injection" ,
121
164
";FileManager;true;contents(atPath:);;;Argument[0];path-injection" ,
122
165
";FileManager;true;contentsEqual(atPath:andPath:);;;Argument[0..1];path-injection" ,
123
166
";FileManager;true;changeCurrentDirectoryPath(_:);;;Argument[0];path-injection" ,
124
167
";FileManager;true;unmountVolume(at:options:completionHandler:);;;Argument[0];path-injection" ,
125
168
// Deprecated FileManager methods:
126
169
";FileManager;true;changeFileAttributes(_:atPath:);;;Argument[1];path-injection" ,
170
+ ";FileManager;true;fileAttributes(atPath:traverseLink:);;;Argument[0];path-injection" ,
127
171
";FileManager;true;directoryContents(atPath:);;;Argument[0];path-injection" ,
128
172
";FileManager;true;createDirectory(atPath:attributes:);;;Argument[0];path-injection" ,
129
173
";FileManager;true;createSymbolicLink(atPath:pathContent:);;;Argument[0..1];path-injection" ,
@@ -146,6 +190,7 @@ private class PathInjectionSinks extends SinkModelCsv {
146
190
";ArchiveByteStream;true;withFileStream(path:mode:options:permissions:_:);;;Argument[0];path-injection" ,
147
191
";Bundle;true;init(url:);;;Argument[0];path-injection" ,
148
192
";Bundle;true;init(path:);;;Argument[0];path-injection" ,
193
+ ";NSURL;writeBookmarkData(_:to:options:);;;Argument[1];path-injection" ,
149
194
// GRDB
150
195
";Database;true;init(path:description:configuration:);;;Argument[0];path-injection" ,
151
196
";DatabasePool;true;init(path:configuration:);;;Argument[0];path-injection" ,
0 commit comments