Skip to content

Commit dadfbcb

Browse files
committed
Ruby: add toString and locations to the new node types
1 parent d59c720 commit dadfbcb

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,13 @@ module API {
186186
/**
187187
* Gets the data-flow node that gives rise to this node, if any.
188188
*/
189-
DataFlow::Node getInducingNode() { this = Impl::MkUse(result) }
189+
DataFlow::Node getInducingNode() {
190+
this = Impl::MkUse(result)
191+
or
192+
this = Impl::MkDef(result)
193+
or
194+
this = Impl::MkMethodCall(result)
195+
}
190196

191197
/** Gets the location of this node. */
192198
Location getLocation() {
@@ -233,15 +239,26 @@ module API {
233239
override string toString() { result = "root" }
234240
}
235241

242+
private string tryGetPath(Node node) {
243+
result = node.getPath()
244+
or
245+
not exists(node.getPath()) and
246+
result = "with no path"
247+
}
248+
236249
/** A node corresponding to the use of an API component. */
237250
class Use extends Node, Impl::MkUse {
238-
override string toString() {
239-
exists(string type | type = "Use " |
240-
result = type + this.getPath()
241-
or
242-
not exists(this.getPath()) and result = type + "with no path"
243-
)
244-
}
251+
override string toString() { result = "Use " + tryGetPath(this) }
252+
}
253+
254+
/** A node corresponding to a value escaping into an API component. */
255+
class Def extends Node, Impl::MkDef {
256+
override string toString() { result = "Def " + tryGetPath(this) }
257+
}
258+
259+
/** A node corresponding to a method call. */
260+
class MethodCall extends Node, Impl::MkMethodCall {
261+
override string toString() { result = "MethodCall " + tryGetPath(this) }
245262
}
246263

247264
/** Gets the root node. */
@@ -443,7 +460,9 @@ module API {
443460
* Holds if there should be a `lbl`-edge from the given call to an argument.
444461
*/
445462
pragma[nomagic]
446-
private predicate argumentStep(string lbl, DataFlow::CallNode call, DataFlowPrivate::ArgumentNode argument) {
463+
private predicate argumentStep(
464+
string lbl, DataFlow::CallNode call, DataFlowPrivate::ArgumentNode argument
465+
) {
447466
exists(DataFlowDispatch::ArgumentPosition argPos |
448467
argument.sourceArgumentOf(call.asExpr(), argPos) and
449468
lbl = getLabelFromArgumentPosition(argPos)
@@ -454,7 +473,9 @@ module API {
454473
* Holds if there should be a `lbl`-edge from the given callable to a parameter.
455474
*/
456475
pragma[nomagic]
457-
private predicate parameterStep(string lbl, DataFlow::Node callable, DataFlowPrivate::ParameterNodeImpl paramNode) {
476+
private predicate parameterStep(
477+
string lbl, DataFlow::Node callable, DataFlowPrivate::ParameterNodeImpl paramNode
478+
) {
458479
exists(DataFlowDispatch::ParameterPosition paramPos |
459480
paramNode.isSourceParameterOf(callable.asExpr().getExpr(), paramPos) and
460481
lbl = getLabelFromParameterPosition(paramPos)

0 commit comments

Comments
 (0)