Skip to content

Commit 8228730

Browse files
committed
Ruby: fix regression for methods in singleton classes
1 parent 30f7380 commit 8228730

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ private module Cached {
413413
// end
414414
// end
415415
// ```
416-
exists(Module target |
416+
exists(Module target, MethodBase caller |
417417
target = m.getSuperClass*() and
418-
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), any(SingletonMethod sm),
419-
target) and
418+
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), caller, target) and
419+
singletonMethod(caller, _, _) and
420420
// Singleton methods declared in a block in the top-level may spuriously end up being seen as singleton
421421
// methods on Object, if the block is actually evaluated in the context of another class.
422422
// The 'self' inside such a singleton method could then be any class, leading to self-calls

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ getTarget
265265
| private.rb:104:1:104:20 | call to new | calls.rb:117:5:117:16 | new |
266266
| private.rb:104:1:104:28 | call to call_m1 | private.rb:91:3:93:5 | call_m1 |
267267
| private.rb:105:1:105:20 | call to new | calls.rb:117:5:117:16 | new |
268+
| toplevel_self_singleton.rb:29:13:29:19 | call to call_me | toplevel_self_singleton.rb:25:9:26:11 | call_me |
269+
| toplevel_self_singleton.rb:30:13:30:20 | call to call_you | toplevel_self_singleton.rb:28:9:31:11 | call_you |
268270
unresolvedCall
269271
| calls.rb:23:9:23:19 | call to singleton_m |
270272
| calls.rb:26:9:26:18 | call to instance_m |
@@ -356,8 +358,6 @@ unresolvedCall
356358
| toplevel_self_singleton.rb:13:9:13:27 | call to ab_singleton_method |
357359
| toplevel_self_singleton.rb:17:12:21:1 | call to new |
358360
| toplevel_self_singleton.rb:19:9:19:27 | call to ab_singleton_method |
359-
| toplevel_self_singleton.rb:29:13:29:19 | call to call_me |
360-
| toplevel_self_singleton.rb:30:13:30:20 | call to call_you |
361361
privateMethod
362362
| calls.rb:1:1:3:3 | foo |
363363
| calls.rb:39:1:41:3 | call_instance_m |

0 commit comments

Comments
 (0)