Skip to content

Commit 3831dc7

Browse files
authored
Merge pull request github#13288 from asgerf/rb/super-and-flow-through
Ruby: two bug fixes
2 parents 6867e94 + cfaa27a commit 3831dc7

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ private Ruby::AstNode getSuperParent(Ruby::Super sup) {
121121
result = sup
122122
or
123123
result = getSuperParent(sup).getParent() and
124-
not result instanceof Ruby::Method
124+
not result instanceof Ruby::Method and
125+
not result instanceof Ruby::SingletonMethod
125126
}
126127

127128
private string getSuperMethodName(Ruby::Super sup) {
128-
exists(Ruby::Method meth |
129-
meth = getSuperParent(sup).getParent() and
129+
exists(Ruby::AstNode meth | meth = getSuperParent(sup).getParent() |
130130
result = any(Method c | toGenerated(c) = meth).getName()
131+
or
132+
result = any(SingletonMethod c | toGenerated(c) = meth).getName()
131133
)
132134
}
133135

ruby/ql/lib/codeql/ruby/typetracking/TypeTrackerSpecific.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,23 @@ private predicate flowThrough(DataFlowPublic::ParameterNode param) {
8989
)
9090
}
9191

92+
/** Holds if there is flow from `arg` to `p` via the call `call`, not counting `new -> initialize` call steps. */
93+
pragma[nomagic]
94+
predicate callStepNoInitialize(
95+
ExprNodes::CallCfgNode call, Node arg, DataFlowPrivate::ParameterNodeImpl p
96+
) {
97+
exists(DataFlowDispatch::ParameterPosition pos |
98+
argumentPositionMatch(call, arg, pos) and
99+
p.isSourceParameterOf(DataFlowDispatch::getTarget(call), pos)
100+
)
101+
}
102+
92103
/** Holds if there is a level step from `nodeFrom` to `nodeTo`, which may depend on the call graph. */
93104
pragma[nomagic]
94105
predicate levelStepCall(Node nodeFrom, Node nodeTo) {
95106
exists(DataFlowPublic::ParameterNode param |
96107
flowThrough(param) and
97-
callStep(nodeTo.asExpr(), nodeFrom, param)
108+
callStepNoInitialize(nodeTo.asExpr(), nodeFrom, param)
98109
)
99110
}
100111

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fixed a bug that would occur when an `initialize` method returns `self` or one of its parameters.
5+
In such cases, the corresponding calls to `new` would be associated with an incorrect return type.
6+
This could result in inaccurate call target resolution and cause false positive alerts.

0 commit comments

Comments
 (0)