Skip to content

Commit 286c894

Browse files
committed
ruby: add DataFlow::MethodCallNode class
1 parent 8d22db8 commit 286c894

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ class CallNode extends LocalSourceNode {
6060
Node getKeywordArgument(string name) { result.asExpr() = node.getKeywordArgument(name) }
6161
}
6262

63+
/** A data-flow node corresponding to a method call in the control-flow graph. */
64+
class MethodCallNode extends CallNode {
65+
private CfgNodes::ExprNodes::MethodCallCfgNode node;
66+
67+
MethodCallNode() { node = this.asExpr() }
68+
69+
/** Gets the name of the the method called by the method call corresponding to this data-flow node */
70+
string getMethodName() { result = node.getExpr().getMethodName() }
71+
}
72+
6373
/**
6474
* An expression, viewed as a node in a data flow graph.
6575
*

ruby/ql/lib/codeql/ruby/frameworks/ActiveStorage.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ private import codeql.ruby.DataFlow
55
private import codeql.ruby.dataflow.FlowSummary
66

77
/** Defines calls to `ActiveStorage::Filename#sanitized` as path sanitizers. */
8-
class ActiveStorageFilenameSanitizedCall extends Path::PathSanitization::Range, DataFlow::CallNode {
8+
class ActiveStorageFilenameSanitizedCall extends Path::PathSanitization::Range,
9+
DataFlow::MethodCallNode {
910
ActiveStorageFilenameSanitizedCall() {
1011
this.getReceiver() =
1112
API::getTopLevelMember("ActiveStorage").getMember("Filename").getAnInstantiation() and
12-
this.asExpr().getExpr().(MethodCall).getMethodName() = "sanitized"
13+
this.getMethodName() = "sanitized"
1314
}
1415
}
1516

ruby/ql/lib/codeql/ruby/frameworks/Files.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module IO {
9999
}
100100

101101
/**
102-
* A `DataFlow::CallNode` that reads data using the `IO` class. For example,
102+
* A `DataFlow::MethodCallNode` that reads data using the `IO` class. For example,
103103
* the `IO.read call in:
104104
*
105105
* ```rb
@@ -112,7 +112,7 @@ module IO {
112112
* filesystem. For working with filesystem accesses specifically, see
113113
* `IOFileReader` or the `FileSystemReadAccess` concept.
114114
*/
115-
class IOReader extends DataFlow::CallNode {
115+
class IOReader extends DataFlow::MethodCallNode {
116116
private boolean classMethodCall;
117117
private string api;
118118

@@ -127,17 +127,15 @@ module IO {
127127
api = "IO" and
128128
exists(IOInstanceStrict ii |
129129
this.getReceiver() = ii and
130-
this.asExpr().getExpr().(MethodCall).getMethodName() =
131-
ioFileReaderMethodName(classMethodCall)
130+
this.getMethodName() = ioFileReaderMethodName(classMethodCall)
132131
)
133132
or
134133
// File instance methods
135134
classMethodCall = false and
136135
api = "File" and
137136
exists(File::FileInstance fi |
138137
this.getReceiver() = fi and
139-
this.asExpr().getExpr().(MethodCall).getMethodName() =
140-
ioFileReaderMethodName(classMethodCall)
138+
this.getMethodName() = ioFileReaderMethodName(classMethodCall)
141139
)
142140
// TODO: enumeration style methods such as `each`, `foreach`, etc.
143141
}
@@ -151,7 +149,7 @@ module IO {
151149
}
152150

153151
/**
154-
* A `DataFlow::CallNode` that reads data from the filesystem using the `IO`
152+
* A `DataFlow::MethodCallNode` that reads data from the filesystem using the `IO`
155153
* class. For example, the `IO.read call in:
156154
*
157155
* ```rb
@@ -219,7 +217,7 @@ module File {
219217
/**
220218
* A call to a `File` method that may return one or more filenames.
221219
*/
222-
class FileModuleFilenameSource extends FileNameSource, DataFlow::CallNode {
220+
class FileModuleFilenameSource extends FileNameSource, DataFlow::MethodCallNode {
223221
FileModuleFilenameSource() {
224222
// Class methods
225223
this =
@@ -232,13 +230,13 @@ module File {
232230
// Instance methods
233231
exists(FileInstance fi |
234232
this.getReceiver() = fi and
235-
this.asExpr().getExpr().(MethodCall).getMethodName() = ["path", "to_path"]
233+
this.getMethodName() = ["path", "to_path"]
236234
)
237235
}
238236
}
239237

240238
private class FileModulePermissionModification extends FileSystemPermissionModification::Range,
241-
DataFlow::CallNode {
239+
DataFlow::MethodCallNode {
242240
private DataFlow::Node permissionArg;
243241

244242
FileModulePermissionModification() {
@@ -321,7 +319,7 @@ module FileUtils {
321319
}
322320

323321
private class FileUtilsPermissionModification extends FileSystemPermissionModification::Range,
324-
DataFlow::CallNode {
322+
DataFlow::MethodCallNode {
325323
private DataFlow::Node permissionArg;
326324

327325
FileUtilsPermissionModification() {

0 commit comments

Comments
 (0)