Skip to content

Commit 08b6a17

Browse files
authored
Merge pull request #7151 from github/ruby/methodcallnode
Ruby: add `getMethodName` predicate to `DataFlow::CallNode` class
2 parents 22ebe68 + c8cdbfa commit 08b6a17

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class CallNode extends LocalSourceNode {
5858

5959
/** Gets the data-flow node corresponding to the named argument of the call corresponding to this data-flow node */
6060
Node getKeywordArgument(string name) { result.asExpr() = node.getKeywordArgument(name) }
61+
62+
/** Gets the name of the the method called by the method call (if any) corresponding to this data-flow node */
63+
string getMethodName() { result = node.getExpr().(MethodCall).getMethodName() }
6164
}
6265

6366
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ActiveStorageFilenameSanitizedCall extends Path::PathSanitization::Range,
99
ActiveStorageFilenameSanitizedCall() {
1010
this.getReceiver() =
1111
API::getTopLevelMember("ActiveStorage").getMember("Filename").getAnInstantiation() and
12-
this.asExpr().getExpr().(MethodCall).getMethodName() = "sanitized"
12+
this.getMethodName() = "sanitized"
1313
}
1414
}
1515

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -232,7 +230,7 @@ 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
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class KernelMethodCall extends DataFlow::CallNode {
2626
)
2727
}
2828

29-
string getMethodName() { result = methodCall.getMethodName() }
30-
3129
int getNumberOfArguments() { result = methodCall.getNumberOfArguments() }
3230
}
3331

0 commit comments

Comments
 (0)