File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
lib/codeql/ruby/dataflow/internal
test/library-tests/modules Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -413,8 +413,17 @@ private module Cached {
413
413
// end
414
414
// end
415
415
// ```
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
+ )
418
427
)
419
428
)
420
429
or
Original file line number Diff line number Diff line change @@ -265,8 +265,6 @@ getTarget
265
265
| private.rb:104:1:104:20 | call to new | calls.rb:117:5:117:16 | new |
266
266
| private.rb:104:1:104:28 | call to call_m1 | private.rb:91:3:93:5 | call_m1 |
267
267
| 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 |
270
268
unresolvedCall
271
269
| calls.rb:23:9:23:19 | call to singleton_m |
272
270
| calls.rb:26:9:26:18 | call to instance_m |
@@ -355,7 +353,9 @@ unresolvedCall
355
353
| private.rb:105:1:105:23 | call to m1 |
356
354
| toplevel_self_singleton.rb:8:1:15:3 | call to do_something |
357
355
| 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 |
358
357
| 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 |
359
359
privateMethod
360
360
| calls.rb:1:1:3:3 | foo |
361
361
| calls.rb:39:1:41:3 | call_instance_m |
You can’t perform that action at this time.
0 commit comments