Skip to content

Commit d7e44a5

Browse files
authored
Merge pull request github#10714 from hvitved/ruby/initialize
Ruby: Model flow through `initialize` constructors
2 parents 0af5300 + b3feb4f commit d7e44a5

File tree

12 files changed

+932
-554
lines changed

12 files changed

+932
-554
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
category: majorAnalysis
3+
---
4+
* Flow through `initialize` constructors is now taken into account. For example, in
5+
```rb
6+
class C
7+
def initialize(x)
8+
@field = x
9+
end
10+
end
11+
12+
C.new(y)
13+
```
14+
there will be flow from `y` to the field `@field` on the constructed `C` object.

ruby/ql/lib/codeql/ruby/ast/Call.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ class Call extends Expr instanceof CallImpl {
5353

5454
/** Gets a potential target of this call, if any. */
5555
final Callable getATarget() {
56-
exists(DataFlowCall c | this = c.asCall().getExpr() |
57-
TCfgScope(result) = [viableCallable(c), viableCallableLambda(c, _)]
56+
exists(DataFlowCall c |
57+
this = c.asCall().getExpr() and
58+
TCfgScope(result) = viableCallableLambda(c, _)
5859
)
60+
or
61+
result = getTarget(this.getAControlFlowNode())
5962
}
6063

6164
override AstNode getAChild(string pred) {

0 commit comments

Comments
 (0)