Skip to content

Commit 1476efb

Browse files
committed
Ruby: restrict to a use of 'self' in singleton methods
1 parent 329ab91 commit 1476efb

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ private module Cached {
413413
// end
414414
// end
415415
// ```
416-
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), _, m.getSuperClass*())
416+
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), any(SingletonMethod sm),
417+
m.getSuperClass*())
417418
)
418419
)
419420
or

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ getTarget
88
| calls.rb:17:1:17:8 | call to bar | calls.rb:13:1:15:3 | bar |
99
| calls.rb:19:1:19:8 | call to foo | calls.rb:1:1:3:3 | foo |
1010
| calls.rb:19:1:19:8 | call to foo | calls.rb:85:1:89:3 | foo |
11-
| calls.rb:23:9:23:19 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
1211
| calls.rb:32:5:32:15 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
1312
| calls.rb:33:5:33:20 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
1413
| calls.rb:37:1:37:13 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
@@ -77,7 +76,6 @@ getTarget
7776
| calls.rb:224:9:224:24 | call to singleton_g | calls.rb:236:1:238:3 | singleton_g |
7877
| calls.rb:224:9:224:24 | call to singleton_g | calls.rb:243:1:245:3 | singleton_g |
7978
| calls.rb:224:9:224:24 | call to singleton_g | calls.rb:251:5:253:7 | singleton_g |
80-
| calls.rb:224:9:224:24 | call to singleton_g | calls.rb:267:1:269:3 | singleton_g |
8179
| calls.rb:228:1:228:22 | call to singleton_a | calls.rb:191:5:194:7 | singleton_a |
8280
| calls.rb:229:1:229:22 | call to singleton_f | calls.rb:218:9:220:11 | singleton_f |
8381
| calls.rb:231:6:231:19 | call to new | calls.rb:117:5:117:16 | new |
@@ -263,8 +261,8 @@ getTarget
263261
| private.rb:104:1:104:20 | call to new | calls.rb:117:5:117:16 | new |
264262
| private.rb:104:1:104:28 | call to call_m1 | private.rb:91:3:93:5 | call_m1 |
265263
| private.rb:105:1:105:20 | call to new | calls.rb:117:5:117:16 | new |
266-
| toplevel_self_singleton.rb:10:9:10:27 | call to ab_singleton_method | toplevel_self_singleton.rb:3:9:4:11 | ab_singleton_method |
267264
unresolvedCall
265+
| calls.rb:23:9:23:19 | call to singleton_m |
268266
| calls.rb:26:9:26:18 | call to instance_m |
269267
| calls.rb:29:5:29:14 | call to instance_m |
270268
| calls.rb:30:5:30:19 | call to instance_m |
@@ -349,6 +347,7 @@ unresolvedCall
349347
| private.rb:100:7:100:29 | call to m1 |
350348
| private.rb:105:1:105:23 | call to m1 |
351349
| toplevel_self_singleton.rb:8:1:12:3 | call to do_something |
350+
| toplevel_self_singleton.rb:10:9:10:27 | call to ab_singleton_method |
352351
privateMethod
353352
| calls.rb:1:1:3:3 | foo |
354353
| calls.rb:39:1:41:3 | call_instance_m |

0 commit comments

Comments
 (0)