Skip to content

Commit e9b96c1

Browse files
committed
Ruby: Account for protected methods in call graph
1 parent 58b7556 commit e9b96c1

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,20 @@ private module Cached {
314314
exists(Module tp |
315315
instanceMethodCall(call, tp, method) and
316316
result = lookupMethod(tp, method) and
317-
if result.(Method).isPrivate()
318-
then
319-
call.getReceiver().getExpr() instanceof SelfVariableAccess and
320-
// For now, we restrict the scope of top-level declarations to their file.
321-
// This may remove some plausible targets, but also removes a lot of
322-
// implausible targets
323-
if result.getEnclosingModule() instanceof Toplevel
324-
then result.getFile() = call.getFile()
317+
(
318+
if result.(Method).isPrivate()
319+
then
320+
call.getReceiver().getExpr() instanceof SelfVariableAccess and
321+
// For now, we restrict the scope of top-level declarations to their file.
322+
// This may remove some plausible targets, but also removes a lot of
323+
// implausible targets
324+
if result.getEnclosingModule() instanceof Toplevel
325+
then result.getFile() = call.getFile()
326+
else any()
325327
else any()
328+
) and
329+
if result.(Method).isProtected()
330+
then result = lookupMethod(call.getExpr().getEnclosingModule().getModule(), method)
326331
else any()
327332
)
328333
or

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ getTarget
188188
| calls.rb:494:9:494:28 | call to new | calls.rb:114:5:114:16 | new |
189189
| calls.rb:494:9:494:32 | call to foo | calls.rb:488:15:490:7 | foo |
190190
| calls.rb:498:1:498:20 | call to new | calls.rb:114:5:114:16 | new |
191-
| calls.rb:498:1:498:24 | call to foo | calls.rb:488:15:490:7 | foo |
192191
| calls.rb:499:1:499:20 | call to new | calls.rb:114:5:114:16 | new |
193192
| calls.rb:499:1:499:24 | call to bar | calls.rb:492:5:495:7 | bar |
194193
| hello.rb:12:5:12:24 | call to include | calls.rb:107:5:107:20 | include |
@@ -294,6 +293,7 @@ unresolvedCall
294293
| calls.rb:482:5:482:15 | call to extend |
295294
| calls.rb:485:1:485:31 | call to singleton |
296295
| calls.rb:488:5:490:7 | call to protected |
296+
| calls.rb:498:1:498:24 | call to foo |
297297
| hello.rb:20:16:20:26 | ... + ... |
298298
| hello.rb:20:16:20:34 | ... + ... |
299299
| hello.rb:20:16:20:40 | ... + ... |

0 commit comments

Comments
 (0)