@@ -7,8 +7,11 @@ import semmle.code.java.controlflow.Guards
77
88/** Models the creation of a path. */
99abstract 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 ( ) ;
1215}
1316
1417/** Models the `java.nio.file.Paths.get` method. */
@@ -20,7 +23,7 @@ class PathsGet extends PathCreation, MethodAccess {
2023 )
2124 }
2225
23- override Expr getInput ( ) { result = this .getAnArgument ( ) }
26+ override Expr getAnInput ( ) { result = this .getAnArgument ( ) }
2427}
2528
2629/** Models the `java.nio.file.FileSystem.getPath` method. */
@@ -32,14 +35,14 @@ class FileSystemGetPath extends PathCreation, MethodAccess {
3235 )
3336 }
3437
35- override Expr getInput ( ) { result = this .getAnArgument ( ) }
38+ override Expr getAnInput ( ) { result = this .getAnArgument ( ) }
3639}
3740
3841/** Models the `new java.io.File(...)` constructor. */
3942class FileCreation extends PathCreation , ClassInstanceExpr {
4043 FileCreation ( ) { this .getConstructedType ( ) instanceof TypeFile }
4144
42- override Expr getInput ( ) {
45+ override Expr getAnInput ( ) {
4346 result = this .getAnArgument ( ) and
4447 // Relevant arguments include those that are not a `File`.
4548 not result .getType ( ) instanceof TypeFile
@@ -55,7 +58,7 @@ class PathResolveSiblingCreation extends PathCreation, MethodAccess {
5558 )
5659 }
5760
58- override Expr getInput ( ) {
61+ override Expr getAnInput ( ) {
5962 result = this .getAnArgument ( ) and
6063 // Relevant arguments are those of type `String`.
6164 result .getType ( ) instanceof TypeString
@@ -71,7 +74,7 @@ class PathResolveCreation extends PathCreation, MethodAccess {
7174 )
7275 }
7376
74- override Expr getInput ( ) {
77+ override Expr getAnInput ( ) {
7578 result = this .getAnArgument ( ) and
7679 // Relevant arguments are those of type `String`.
7780 result .getType ( ) instanceof TypeString
@@ -87,14 +90,14 @@ class PathOfCreation extends PathCreation, MethodAccess {
8790 )
8891 }
8992
90- override Expr getInput ( ) { result = this .getAnArgument ( ) }
93+ override Expr getAnInput ( ) { result = this .getAnArgument ( ) }
9194}
9295
9396/** Models the `new java.io.FileWriter(...)` constructor. */
9497class FileWriterCreation extends PathCreation , ClassInstanceExpr {
9598 FileWriterCreation ( ) { this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileWriter" ) }
9699
97- override Expr getInput ( ) {
100+ override Expr getAnInput ( ) {
98101 result = this .getAnArgument ( ) and
99102 // Relevant arguments are those of type `String`.
100103 result .getType ( ) instanceof TypeString
@@ -105,7 +108,7 @@ class FileWriterCreation extends PathCreation, ClassInstanceExpr {
105108class FileReaderCreation extends PathCreation , ClassInstanceExpr {
106109 FileReaderCreation ( ) { this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileReader" ) }
107110
108- override Expr getInput ( ) {
111+ override Expr getAnInput ( ) {
109112 result = this .getAnArgument ( ) and
110113 // Relevant arguments are those of type `String`.
111114 result .getType ( ) instanceof TypeString
@@ -118,7 +121,7 @@ class FileInputStreamCreation extends PathCreation, ClassInstanceExpr {
118121 this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileInputStream" )
119122 }
120123
121- override Expr getInput ( ) {
124+ override Expr getAnInput ( ) {
122125 result = this .getAnArgument ( ) and
123126 // Relevant arguments are those of type `String`.
124127 result .getType ( ) instanceof TypeString
@@ -131,7 +134,7 @@ class FileOutputStreamCreation extends PathCreation, ClassInstanceExpr {
131134 this .getConstructedType ( ) .hasQualifiedName ( "java.io" , "FileOutputStream" )
132135 }
133136
134- override Expr getInput ( ) {
137+ override Expr getAnInput ( ) {
135138 result = this .getAnArgument ( ) and
136139 // Relevant arguments are those of type `String`.
137140 result .getType ( ) instanceof TypeString
@@ -154,7 +157,7 @@ private predicate inWeakCheck(Expr e) {
154157// Ignore cases where the variable has been checked somehow,
155158// but allow some particularly obviously bad cases.
156159predicate guarded ( VarAccess e ) {
157- exists ( PathCreation p | e = p .getInput ( ) ) and
160+ exists ( PathCreation p | e = p .getAnInput ( ) ) and
158161 exists ( ConditionBlock cb , Expr c |
159162 cb .getCondition ( ) .getAChildExpr * ( ) = c and
160163 c = e .getVariable ( ) .getAnAccess ( ) and
0 commit comments