@@ -7,8 +7,11 @@ import semmle.code.java.controlflow.Guards
7
7
8
8
/** Models the creation of a path. */
9
9
abstract class PathCreation extends Expr {
10
- /** Gets an input that is used in the creation of this path. */
11
- abstract Expr getInput ( ) ;
10
+ /**
11
+ * Gets an input that is used in the creation of this path.
12
+ * This excludes inputs of type `File` and `Path`.
13
+ */
14
+ abstract Expr getAnInput ( ) ;
12
15
}
13
16
14
17
/** Models the `java.nio.file.Paths.get` method. */
@@ -20,7 +23,7 @@ class PathsGet extends PathCreation, MethodAccess {
20
23
)
21
24
}
22
25
23
- override Expr getInput ( ) { result = this .getAnArgument ( ) }
26
+ override Expr getAnInput ( ) { result = this .getAnArgument ( ) }
24
27
}
25
28
26
29
/** Models the `java.nio.file.FileSystem.getPath` method. */
@@ -32,14 +35,14 @@ class FileSystemGetPath extends PathCreation, MethodAccess {
32
35
)
33
36
}
34
37
35
- override Expr getInput ( ) { result = this .getAnArgument ( ) }
38
+ override Expr getAnInput ( ) { result = this .getAnArgument ( ) }
36
39
}
37
40
38
41
/** Models the `new java.io.File(...)` constructor. */
39
42
class FileCreation extends PathCreation , ClassInstanceExpr {
40
43
FileCreation ( ) { this .getConstructedType ( ) instanceof TypeFile }
41
44
42
- override Expr getInput ( ) {
45
+ override Expr getAnInput ( ) {
43
46
result = this .getAnArgument ( ) and
44
47
// Relevant arguments include those that are not a `File`.
45
48
not result .getType ( ) instanceof TypeFile
@@ -55,7 +58,7 @@ class PathResolveSiblingCreation extends PathCreation, MethodAccess {
55
58
)
56
59
}
57
60
58
- override Expr getInput ( ) {
61
+ override Expr getAnInput ( ) {
59
62
result = this .getAnArgument ( ) and
60
63
// Relevant arguments are those of type `String`.
61
64
result .getType ( ) instanceof TypeString
@@ -71,7 +74,7 @@ class PathResolveCreation extends PathCreation, MethodAccess {
71
74
)
72
75
}
73
76
74
- override Expr getInput ( ) {
77
+ override Expr getAnInput ( ) {
75
78
result = this .getAnArgument ( ) and
76
79
// Relevant arguments are those of type `String`.
77
80
result .getType ( ) instanceof TypeString
@@ -87,14 +90,14 @@ class PathOfCreation extends PathCreation, MethodAccess {
87
90
)
88
91
}
89
92
90
- override Expr getInput ( ) { result = this .getAnArgument ( ) }
93
+ override Expr getAnInput ( ) { result = this .getAnArgument ( ) }
91
94
}
92
95
93
96
/** Models the `new java.io.FileWriter(...)` constructor. */
94
97
class FileWriterCreation extends PathCreation , ClassInstanceExpr {
95
98
FileWriterCreation ( ) { this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileWriter" ) }
96
99
97
- override Expr getInput ( ) {
100
+ override Expr getAnInput ( ) {
98
101
result = this .getAnArgument ( ) and
99
102
// Relevant arguments are those of type `String`.
100
103
result .getType ( ) instanceof TypeString
@@ -105,7 +108,7 @@ class FileWriterCreation extends PathCreation, ClassInstanceExpr {
105
108
class FileReaderCreation extends PathCreation , ClassInstanceExpr {
106
109
FileReaderCreation ( ) { this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileReader" ) }
107
110
108
- override Expr getInput ( ) {
111
+ override Expr getAnInput ( ) {
109
112
result = this .getAnArgument ( ) and
110
113
// Relevant arguments are those of type `String`.
111
114
result .getType ( ) instanceof TypeString
@@ -118,7 +121,7 @@ class FileInputStreamCreation extends PathCreation, ClassInstanceExpr {
118
121
this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileInputStream" )
119
122
}
120
123
121
- override Expr getInput ( ) {
124
+ override Expr getAnInput ( ) {
122
125
result = this .getAnArgument ( ) and
123
126
// Relevant arguments are those of type `String`.
124
127
result .getType ( ) instanceof TypeString
@@ -131,7 +134,7 @@ class FileOutputStreamCreation extends PathCreation, ClassInstanceExpr {
131
134
this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileOutputStream" )
132
135
}
133
136
134
- override Expr getInput ( ) {
137
+ override Expr getAnInput ( ) {
135
138
result = this .getAnArgument ( ) and
136
139
// Relevant arguments are those of type `String`.
137
140
result .getType ( ) instanceof TypeString
@@ -154,7 +157,7 @@ private predicate inWeakCheck(Expr e) {
154
157
// Ignore cases where the variable has been checked somehow,
155
158
// but allow some particularly obviously bad cases.
156
159
predicate guarded ( VarAccess e ) {
157
- exists ( PathCreation p | e = p .getInput ( ) ) and
160
+ exists ( PathCreation p | e = p .getAnInput ( ) ) and
158
161
exists ( ConditionBlock cb , Expr c |
159
162
cb .getCondition ( ) .getAChildExpr * ( ) = c and
160
163
c = e .getVariable ( ) .getAnAccess ( ) and
0 commit comments