Skip to content

Commit 826b621

Browse files
committed
Ruby: Include self parameters in type tracking flow-through logic
1 parent 3cdb277 commit 826b621

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,12 @@ private class NewCall extends DataFlowCall {
940940
abstract class ReturningNode extends Node {
941941
/** Gets the kind of this return node. */
942942
abstract ReturnKind getKind();
943+
944+
pragma[nomagic]
945+
predicate hasKind(ReturnKind kind, CfgScope scope) {
946+
kind = this.getKind() and
947+
scope = this.(NodeImpl).getCfgScope()
948+
}
943949
}
944950

945951
/** A data-flow node that represents a value returned by a callable. */
@@ -1060,10 +1066,8 @@ private module ReturnNodes {
10601066
SynthReturnNode() { this = TSynthReturnNode(scope, kind) }
10611067

10621068
/** Gets a syntactic return node that flows into this synthetic node. */
1063-
ReturningNode getAnInput() {
1064-
result.(NodeImpl).getCfgScope() = scope and
1065-
result.getKind() = kind
1066-
}
1069+
pragma[nomagic]
1070+
ReturningNode getAnInput() { result.hasKind(kind, scope) }
10671071

10681072
override ReturnKind getKind() { result = kind }
10691073

ruby/ql/lib/codeql/ruby/typetracking/TypeTrackerSpecific.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ predicate jumpStep = DataFlowPrivate::jumpStep/2;
8080
pragma[nomagic]
8181
private predicate flowThrough(DataFlowPublic::ParameterNode param) {
8282
exists(DataFlowPrivate::ReturningNode returnNode, DataFlowDispatch::ReturnKind rk |
83-
DataFlowPrivate::LocalFlow::getParameterDefNode(param.getParameter())
84-
.(TypeTrackingNode)
85-
.flowsTo(returnNode) and
86-
rk = returnNode.getKind()
83+
param.flowsTo(returnNode) and
84+
returnNode.hasKind(rk, param.(DataFlowPrivate::NodeImpl).getCfgScope())
8785
|
8886
rk instanceof DataFlowDispatch::NormalReturnKind
8987
or

ruby/ql/test/library-tests/modules/callgraph.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ getTarget
153153
| calls.rb:383:1:383:23 | call to instance | calls.rb:326:5:328:7 | instance |
154154
| calls.rb:383:1:383:23 | call to instance | calls.rb:336:5:338:7 | instance |
155155
| calls.rb:383:1:383:23 | call to instance | calls.rb:342:5:344:7 | instance |
156+
| calls.rb:383:1:383:23 | call to instance | calls.rb:375:5:377:7 | instance |
156157
| calls.rb:388:13:388:48 | call to puts | calls.rb:102:5:102:30 | puts |
157158
| calls.rb:392:13:392:22 | call to singleton1 | calls.rb:387:9:389:11 | singleton1 |
158159
| calls.rb:392:13:392:22 | call to singleton1 | calls.rb:422:9:424:11 | singleton1 |

0 commit comments

Comments
 (0)