1
1
/**
2
- * Provides a utility classes and predicates for queries reasoning about Kernel.open and related methods.
2
+ * Provides utility classes and predicates for reasoning about ` Kernel.open` and related methods.
3
3
*/
4
4
5
5
private import codeql.ruby.AST
@@ -9,36 +9,28 @@ private import codeql.ruby.ApiGraphs
9
9
private import codeql.ruby.frameworks.core.Kernel:: Kernel
10
10
11
11
/** A call to a method that might access a file or start a process. */
12
- abstract class AmbiguousPathCall extends DataFlow:: CallNode {
13
- /** Gets the name for the method being called. */
14
- abstract string getName ( ) ;
15
-
16
- /** Gets the name for a safer method that can be used instead. */
17
- abstract string getReplacement ( ) ;
18
-
19
- /** Gets the argument that specifies the path to be accessed. */
20
- abstract DataFlow:: Node getPathArgument ( ) ;
21
- }
22
-
23
- private class KernelOpenCall extends KernelMethodCall , AmbiguousPathCall {
24
- KernelOpenCall ( ) { this .getMethodName ( ) = "open" }
25
-
26
- override string getName ( ) { result = "Kernel.open" }
12
+ class AmbiguousPathCall extends DataFlow:: CallNode {
13
+ string name ;
27
14
28
- override string getReplacement ( ) { result = "File.open" }
29
-
30
- override DataFlow:: Node getPathArgument ( ) { result = this .getArgument ( 0 ) }
31
- }
32
-
33
- private class IOReadCall extends DataFlow:: CallNode , AmbiguousPathCall {
34
- IOReadCall ( ) {
15
+ AmbiguousPathCall ( ) {
16
+ this .( KernelMethodCall ) .getMethodName ( ) = "open" and
17
+ name = "Kernel.open"
18
+ or
35
19
this = API:: getTopLevelMember ( "IO" ) .getAMethodCall ( "read" ) and
36
- not this = API:: getTopLevelMember ( "File" ) .getAMethodCall ( "read" ) // needed in e.g. opal/opal, where some calls have both paths, but I'm not sure why
20
+ not this = API:: getTopLevelMember ( "File" ) .getAMethodCall ( "read" ) and // needed in e.g. opal/opal, where some calls have both paths, but I'm not sure why
21
+ name = "IO.read"
37
22
}
38
23
39
- override string getName ( ) { result = "IO.read" }
24
+ /** Gets the name for the method being called. */
25
+ string getName ( ) { result = name }
40
26
41
- override string getReplacement ( ) { result = "File.read" }
27
+ /** Gets the name for a safer method that can be used instead. */
28
+ string getReplacement ( ) {
29
+ result = "File.read" and name = "IO.read"
30
+ or
31
+ result = "File.open" and name = "Kernel.open"
32
+ }
42
33
43
- override DataFlow:: Node getPathArgument ( ) { result = this .getArgument ( 0 ) }
34
+ /** Gets the argument that specifies the path to be accessed. */
35
+ DataFlow:: Node getPathArgument ( ) { result = this .getArgument ( 0 ) }
44
36
}
0 commit comments