Skip to content

Commit 0e9cd1e

Browse files
committed
factor out methodName to a field in KernelMethodCall
1 parent e24f041 commit 0e9cd1e

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

ruby/ql/lib/codeql/ruby/frameworks/core/Kernel.qll

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,26 @@ module Kernel {
1818
* providing a specific receiver as in `Kernel.exit`.
1919
*/
2020
class KernelMethodCall extends DataFlow::CallNode {
21+
string methodName;
22+
2123
KernelMethodCall() {
22-
this = API::getTopLevelMember("Kernel").getAMethodCall(_)
24+
this = API::getTopLevelMember("Kernel").getAMethodCall(methodName)
2325
or
2426
this.asExpr().getExpr() instanceof UnknownMethodCall and
27+
methodName = super.getMethodName() and
2528
(
2629
this.getReceiver().asExpr().getExpr() instanceof SelfVariableAccess and
27-
isPrivateKernelMethod(this.getMethodName())
30+
isPrivateKernelMethod(methodName)
2831
or
29-
isPublicKernelMethod(this.getMethodName())
32+
isPublicKernelMethod(methodName)
3033
)
3134
}
35+
36+
/**
37+
* Gets which method of `Kernel` is called.
38+
* Works even when the call is a `super(...)` call.
39+
*/
40+
string getKernelMethod() { result = methodName }
3241
}
3342

3443
/**
@@ -93,7 +102,7 @@ module Kernel {
93102
* Ruby documentation: https://docs.ruby-lang.org/en/3.0.0/Kernel.html#method-i-system
94103
*/
95104
class KernelSystemCall extends SystemCommandExecution::Range instanceof KernelMethodCall {
96-
KernelSystemCall() { this.getMethodName() = "system" }
105+
KernelSystemCall() { this.getKernelMethod() = "system" }
97106

98107
override DataFlow::Node getAnArgument() { result = super.getArgument(_) }
99108

@@ -109,7 +118,7 @@ module Kernel {
109118
* Ruby documentation: https://docs.ruby-lang.org/en/3.0.0/Kernel.html#method-i-exec
110119
*/
111120
class KernelExecCall extends SystemCommandExecution::Range instanceof KernelMethodCall {
112-
KernelExecCall() { this.getMethodName() = "exec" }
121+
KernelExecCall() { this.getKernelMethod() = "exec" }
113122

114123
override DataFlow::Node getAnArgument() { result = super.getArgument(_) }
115124

@@ -130,7 +139,7 @@ module Kernel {
130139
* ```
131140
*/
132141
class KernelSpawnCall extends SystemCommandExecution::Range instanceof KernelMethodCall {
133-
KernelSpawnCall() { this.getMethodName() = "spawn" }
142+
KernelSpawnCall() { this.getKernelMethod() = "spawn" }
134143

135144
override DataFlow::Node getAnArgument() { result = super.getArgument(_) }
136145

@@ -149,7 +158,7 @@ module Kernel {
149158
* ```
150159
*/
151160
class EvalCallCodeExecution extends CodeExecution::Range, KernelMethodCall {
152-
EvalCallCodeExecution() { this.getMethodName() = "eval" }
161+
EvalCallCodeExecution() { this.getKernelMethod() = "eval" }
153162

154163
override DataFlow::Node getCode() { result = this.getArgument(0) }
155164
}
@@ -163,7 +172,7 @@ module Kernel {
163172
* ```
164173
*/
165174
class SendCallCodeExecution extends CodeExecution::Range, KernelMethodCall {
166-
SendCallCodeExecution() { this.getMethodName() = "send" }
175+
SendCallCodeExecution() { this.getKernelMethod() = "send" }
167176

168177
override DataFlow::Node getCode() { result = this.getArgument(0) }
169178

@@ -183,15 +192,15 @@ module Kernel {
183192
/** A call to e.g. `Kernel.load` that accesses a file. */
184193
private class KernelFileAccess extends FileSystemAccess::Range instanceof KernelMethodCall {
185194
KernelFileAccess() {
186-
super.getMethodName() = ["load", "require", "require_relative", "autoload", "autoload?"]
195+
super.getKernelMethod() = ["load", "require", "require_relative", "autoload", "autoload?"]
187196
}
188197

189198
override DataFlow::Node getAPathArgument() {
190199
result = super.getArgument(0) and
191-
super.getMethodName() = ["load", "require", "require_relative"]
200+
super.getKernelMethod() = ["load", "require", "require_relative"]
192201
or
193202
result = super.getArgument(1) and
194-
super.getMethodName() = ["autoload", "autoload?"]
203+
super.getKernelMethod() = ["autoload", "autoload?"]
195204
}
196205
}
197206
}

0 commit comments

Comments
 (0)