Skip to content

Commit dd86843

Browse files
committed
Ruby: add asCallable()
1 parent 6feda75 commit dd86843

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ module API {
200200
pragma[inline_late]
201201
DataFlow::Node asSink() { result = asSinkInline(this) }
202202

203+
/**
204+
* Gets a callable that can reach this sink.
205+
*
206+
* For example:
207+
* ```ruby
208+
* Foo.bar do |x| # API::getTopLevelMember("Foo").getMethod("bar").getBlock().asCallable()
209+
* end
210+
*
211+
* class Baz
212+
* def m # API::getTopLevelMember("Foo").getMethod("bar").getArgument(0).getMethod("m").asCallable()
213+
* end
214+
* end
215+
* Foo.bar(Baz.new)
216+
* ```
217+
*/
218+
bindingset[this]
219+
pragma[inline_late]
220+
DataFlow::CallableNode asCallable() { Impl::asCallable(this.getAnEpsilonSuccessor(), result) }
221+
203222
/**
204223
* Get a data-flow node that transitively flows to this value, provided that this value corresponds
205224
* to a sink.
@@ -1196,6 +1215,11 @@ module API {
11961215
)
11971216
}
11981217

1218+
cached
1219+
predicate asCallable(Node apiNode, DataFlow::CallableNode callable) {
1220+
apiNode = getBackwardStartNode(callable)
1221+
}
1222+
11991223
cached
12001224
predicate contentEdge(Node pred, DataFlow::Content content, Node succ) {
12011225
exists(

0 commit comments

Comments
 (0)