Skip to content

Commit 75b7236

Browse files
committed
Ruby: add toString and locations to the new node types
1 parent 7373a50 commit 75b7236

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

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

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ module API {
203203
/**
204204
* Gets the data-flow node that gives rise to this node, if any.
205205
*/
206-
DataFlow::Node getInducingNode() { this = Impl::MkUse(result) }
206+
DataFlow::Node getInducingNode() {
207+
this = Impl::MkUse(result)
208+
or
209+
this = Impl::MkDef(result)
210+
or
211+
this = Impl::MkMethodAccessNode(result)
212+
}
207213

208214
/** Gets the location of this node. */
209215
Location getLocation() {
@@ -250,15 +256,26 @@ module API {
250256
override string toString() { result = "root" }
251257
}
252258

259+
private string tryGetPath(Node node) {
260+
result = node.getPath()
261+
or
262+
not exists(node.getPath()) and
263+
result = "with no path"
264+
}
265+
253266
/** A node corresponding to the use of an API component. */
254267
class Use extends Node, Impl::MkUse {
255-
override string toString() {
256-
exists(string type | type = "Use " |
257-
result = type + this.getPath()
258-
or
259-
not exists(this.getPath()) and result = type + "with no path"
260-
)
261-
}
268+
override string toString() { result = "Use " + tryGetPath(this) }
269+
}
270+
271+
/** A node corresponding to a value escaping into an API component. */
272+
class Def extends Node, Impl::MkDef {
273+
override string toString() { result = "Def " + tryGetPath(this) }
274+
}
275+
276+
/** A node corresponding to the method being invoked at a method call. */
277+
class MethodAccessNode extends Node, Impl::MkMethodAccessNode {
278+
override string toString() { result = "MethodAccessNode " + tryGetPath(this) }
262279
}
263280

264281
/** Gets the root node. */
@@ -304,7 +321,7 @@ module API {
304321
/** The root of the API graph. */
305322
MkRoot() or
306323
/** The method accessed at `call`, synthetically treated as a separate object. */
307-
MkMethodCall(DataFlow::CallNode call) { isUse(call) } or
324+
MkMethodAccessNode(DataFlow::CallNode call) { isUse(call) } or
308325
/** A use of an API member at the node `nd`. */
309326
MkUse(DataFlow::Node nd) { isUse(nd) } or
310327
/** A value that escapes into an API at the node `nd` */
@@ -349,7 +366,7 @@ module API {
349366
ref.asExpr() = c and
350367
read = c.getExpr()
351368
)
352-
// note: method calls are not handled here as there is no DataFlow::Node for the intermediate MkMethodCall API node
369+
// note: method calls are not handled here as there is no DataFlow::Node for the intermediate MkMethodAccessNode API node
353370
}
354371

355372
pragma[nomagic]
@@ -459,7 +476,9 @@ module API {
459476
* Holds if there should be a `lbl`-edge from the given call to an argument.
460477
*/
461478
pragma[nomagic]
462-
private predicate argumentStep(string lbl, DataFlow::CallNode call, DataFlowPrivate::ArgumentNode argument) {
479+
private predicate argumentStep(
480+
string lbl, DataFlow::CallNode call, DataFlowPrivate::ArgumentNode argument
481+
) {
463482
exists(DataFlowDispatch::ArgumentPosition argPos |
464483
argument.sourceArgumentOf(call.asExpr(), argPos) and
465484
lbl = getLabelFromArgumentPosition(argPos)
@@ -470,7 +489,9 @@ module API {
470489
* Holds if there should be a `lbl`-edge from the given callable to a parameter.
471490
*/
472491
pragma[nomagic]
473-
private predicate parameterStep(string lbl, DataFlow::Node callable, DataFlowPrivate::ParameterNodeImpl paramNode) {
492+
private predicate parameterStep(
493+
string lbl, DataFlow::Node callable, DataFlowPrivate::ParameterNodeImpl paramNode
494+
) {
474495
exists(DataFlowDispatch::ParameterPosition paramPos |
475496
paramNode.isSourceParameterOf(callable.asExpr().getExpr(), paramPos) and
476497
lbl = getLabelFromParameterPosition(paramPos)
@@ -564,11 +585,11 @@ module API {
564585
pred = MkUse(receiver) and
565586
useNodeReachesReceiver(receiver, call) and
566587
lbl = Label::method(call.getMethodName()) and
567-
succ = MkMethodCall(call)
588+
succ = MkMethodAccessNode(call)
568589
)
569590
or
570591
// from method call node to return and arguments
571-
pred = MkMethodCall(call) and
592+
pred = MkMethodAccessNode(call) and
572593
(
573594
lbl = Label::return() and
574595
succ = MkUse(call)

0 commit comments

Comments
 (0)