File tree Expand file tree Collapse file tree
lib/codeql/ruby/dataflow/internal
test/library-tests/modules Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -413,8 +413,17 @@ private module Cached {
413413 // end
414414 // end
415415 // ```
416- selfInMethod ( sourceNode .( SsaSelfDefinitionNode ) .getVariable ( ) , any ( SingletonMethod sm ) ,
417- m .getSuperClass * ( ) )
416+ exists ( Module target |
417+ target = m .getSuperClass * ( ) and
418+ selfInMethod ( sourceNode .( SsaSelfDefinitionNode ) .getVariable ( ) , any ( SingletonMethod sm ) ,
419+ target ) and
420+ // Singleton methods declared in a block in the top-level may spuriously end up being seen as singleton
421+ // methods on Object, if the block is actually evaluated in the context of another class.
422+ // The 'self' inside such a singleton method could then be any class, leading to self-calls
423+ // being resolved to arbitrary singleton methods.
424+ // To remedy this, we do not allow following super-classes all the way to Object.
425+ not ( m != target and target = TResolved ( "Object" ) )
426+ )
418427 )
419428 )
420429 or
Original file line number Diff line number Diff line change @@ -265,8 +265,6 @@ 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:13:9:13:27 | call to ab_singleton_method | toplevel_self_singleton.rb:3:9:4:11 | ab_singleton_method |
269- | toplevel_self_singleton.rb:19:9:19:27 | call to ab_singleton_method | toplevel_self_singleton.rb:3:9:4:11 | ab_singleton_method |
270268unresolvedCall
271269| calls.rb:23:9:23:19 | call to singleton_m |
272270| calls.rb:26:9:26:18 | call to instance_m |
@@ -355,7 +353,9 @@ unresolvedCall
355353| private.rb:105:1:105:23 | call to m1 |
356354| toplevel_self_singleton.rb:8:1:15:3 | call to do_something |
357355| toplevel_self_singleton.rb:10:9:10:27 | call to ab_singleton_method |
356+ | toplevel_self_singleton.rb:13:9:13:27 | call to ab_singleton_method |
358357| toplevel_self_singleton.rb:17:12:21:1 | call to new |
358+ | toplevel_self_singleton.rb:19:9:19:27 | call to ab_singleton_method |
359359privateMethod
360360| calls.rb:1:1:3:3 | foo |
361361| calls.rb:39:1:41:3 | call_instance_m |
You can’t perform that action at this time.
0 commit comments