Skip to content

Commit b197eff

Browse files
committed
Ruby: Add missing edges to the call graph for singleton methods
1 parent ab22f93 commit b197eff

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,12 @@ private DataFlow::LocalSourceNode trackModule(Module tp, TypeTracker t) {
432432
resolveConstantReadAccess(result.asExpr().getExpr()) = tp
433433
or
434434
// `self` reference to Module
435-
exists(Scope scope |
436-
scope = result.(SsaSelfDefinitionNode).getSelfScope() and
435+
exists(Scope scope | scope = result.(SsaSelfDefinitionNode).getSelfScope() |
437436
tp = scope.(ModuleBase).getModule() and
438437
not scope instanceof Toplevel // handled in `trackInstance`
438+
or
439+
scope = result.(SsaSelfDefinitionNode).getSelfScope() and
440+
tp = scope.(SingletonMethod).getEnclosingModule().getModule()
439441
)
440442
)
441443
or

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ getTarget
6363
| calls.rb:167:1:167:15 | call to private_on_main | calls.rb:164:1:165:3 | private_on_main |
6464
| calls.rb:171:9:171:24 | call to singleton_b | calls.rb:174:5:176:7 | singleton_b |
6565
| calls.rb:175:9:175:24 | call to singleton_c | calls.rb:178:5:179:7 | singleton_c |
66+
| calls.rb:182:9:182:24 | call to singleton_a | calls.rb:170:5:172:7 | singleton_a |
6667
| calls.rb:186:1:186:22 | call to singleton_a | calls.rb:170:5:172:7 | singleton_a |
6768
| hello.rb:12:5:12:24 | call to include | calls.rb:92:5:92:20 | include |
6869
| hello.rb:14:16:14:20 | call to hello | hello.rb:2:5:4:7 | hello |
@@ -114,7 +115,6 @@ unresolvedCall
114115
| calls.rb:135:1:135:8 | call to [] |
115116
| calls.rb:135:4:135:5 | - ... |
116117
| calls.rb:135:32:135:36 | call to abs |
117-
| calls.rb:182:9:182:24 | call to singleton_a |
118118
| hello.rb:20:16:20:26 | ... + ... |
119119
| hello.rb:20:16:20:34 | ... + ... |
120120
| hello.rb:20:16:20:40 | ... + ... |

0 commit comments

Comments
 (0)