Skip to content

Commit 3c33907

Browse files
authored
Merge pull request #10245 from hvitved/ruby/simplify-track-instance
Ruby: Exclude top-level `self` accesses from `trackModule`
2 parents 710ba3c + 4d48516 commit 3c33907

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,18 @@ private DataFlow::LocalSourceNode trackSingletonMethod(MethodBase m, string name
425425
name = m.getName()
426426
}
427427

428-
private SsaSelfDefinitionNode selfInModule(Module tp) {
429-
tp = result.getSelfScope().(ModuleBase).getModule()
430-
}
431-
432428
private DataFlow::LocalSourceNode trackModule(Module tp, TypeTracker t) {
433429
t.start() and
434430
(
435431
// ConstantReadAccess to Module
436432
resolveConstantReadAccess(result.asExpr().getExpr()) = tp
437433
or
438434
// `self` reference to Module
439-
result = selfInModule(tp)
435+
exists(Scope scope |
436+
scope = result.(SsaSelfDefinitionNode).getSelfScope() and
437+
tp = scope.(ModuleBase).getModule() and
438+
not scope instanceof Toplevel // handled in `trackInstance`
439+
)
440440
)
441441
or
442442
exists(TypeTracker t2, StepSummary summary |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ getTarget
7676
| modules.rb:96:3:96:14 | call to include | calls.rb:92:5:92:20 | include |
7777
| modules.rb:102:3:102:16 | call to prepend | calls.rb:93:5:93:20 | prepend |
7878
| modules_rec.rb:8:3:8:11 | call to prepend | calls.rb:93:5:93:20 | prepend |
79-
| modules_rec.rb:11:1:11:9 | call to prepend | calls.rb:93:5:93:20 | prepend |
8079
| private.rb:2:3:3:5 | call to private | calls.rb:94:5:94:20 | private |
8180
| private.rb:10:3:10:19 | call to private | calls.rb:94:5:94:20 | private |
8281
| private.rb:12:3:12:9 | call to private | calls.rb:94:5:94:20 | private |
@@ -115,6 +114,7 @@ unresolvedCall
115114
| hello.rb:20:16:20:26 | ... + ... |
116115
| hello.rb:20:16:20:34 | ... + ... |
117116
| hello.rb:20:16:20:40 | ... + ... |
117+
| modules_rec.rb:11:1:11:9 | call to prepend |
118118
| private.rb:23:3:24:5 | call to private_class_method |
119119
| private.rb:28:3:28:32 | call to private_class_method |
120120
| private.rb:34:1:34:14 | call to private1 |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ getADeclaration
7272
| calls.rb:97:1:100:3 | Object | calls.rb:97:1:100:3 | Object |
7373
| calls.rb:97:1:100:3 | Object | hello.rb:1:1:22:3 | hello.rb |
7474
| calls.rb:97:1:100:3 | Object | modules.rb:1:1:121:4 | modules.rb |
75-
| calls.rb:97:1:100:3 | Object | modules_rec.rb:1:1:11:10 | modules_rec.rb |
75+
| calls.rb:97:1:100:3 | Object | modules_rec.rb:1:1:11:26 | modules_rec.rb |
7676
| calls.rb:97:1:100:3 | Object | private.rb:1:1:60:3 | private.rb |
7777
| calls.rb:102:1:104:3 | Hash | calls.rb:102:1:104:3 | Hash |
7878
| calls.rb:106:1:117:3 | Array | calls.rb:106:1:117:3 | Array |

ruby/ql/test/library-tests/modules/modules_rec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class A < B
88
prepend B
99
end
1010

11-
prepend A
11+
prepend A # NoMethodError

0 commit comments

Comments
 (0)