Skip to content

Commit f18e503

Browse files
committed
Address comments by @tausbn
1 parent cdfe749 commit f18e503

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

ql/src/codeql_ruby/ApiGraphs.qll

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module API {
4747
* Gets a call to a method on the receiver represented by this API component.
4848
*/
4949
DataFlow::CallNode getAMethodCall(string method) {
50-
result = getMethodCallNode(method).getAnImmediateUse()
50+
result = getReturn(method).getAnImmediateUse()
5151
}
5252

5353
/**
@@ -91,12 +91,9 @@ module API {
9191
Node getInstance() { result = getASuccessor(Label::instance()) }
9292

9393
/**
94-
* Gets a node representing the result of calling a method on a receiver represented by this node.
95-
*
96-
* This predicate may have multiple results when there are multiple of the method on this API component.
97-
* Consider using `getAMethodCall()` if there is a need to distinguish between individual calls.
94+
* Gets a node representing the result of calling a method on the receiver represented by this node.
9895
*/
99-
Node getMethodCallNode(string method) { result = getASuccessor(Label::return(method)) }
96+
Node getReturn(string method) { result = getASuccessor(Label::return(method)) }
10097

10198
/**
10299
* Gets a `new` call to the function represented by this API component.
@@ -227,9 +224,6 @@ module API {
227224
*/
228225
Node moduleImport(string m) { result = Impl::MkModuleImport(m) }
229226

230-
/** Gets a node corresponding to the built-in with the given name, if any. */
231-
Node builtin(string n) { result = moduleImport("builtins").getMember(n) }
232-
233227
/**
234228
* Provides the actual implementation of API graphs, cached for performance.
235229
*
@@ -330,6 +324,7 @@ module API {
330324
ref.asExpr().getExpr() = call
331325
)
332326
or
327+
// Calling the `new` method on a node that is a use of `base`, which creates a new instance
333328
exists(MethodCall call, DataFlow::Node node |
334329
pred.flowsTo(node) and
335330
node.asExpr().getExpr() = call.getReceiver() and

ql/test/library-tests/dataflow/api-graphs/test1.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
rescue AttributeError => e #$ use=moduleImport("AttributeError") // missing because there is no dataflow Node for AttributeError
99
Kernel.print(e) #$ use=moduleImport("Kernel").getReturn("print")
1010
end
11-
Unknown.new.run #$ use=moduleImport("Unknown").instance.getReturn("run")
11+
Unknown.new.run #$ use=moduleImport("Unknown").instance.getReturn("run")
12+
Foo::Bar::Baz #$ use=moduleImport("Foo").getMember("Bar").getMember("Baz")

0 commit comments

Comments
 (0)