File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed
Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff 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
127128private 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
Original file line number Diff line number Diff 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. */
93104pragma [ nomagic]
94105predicate 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
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments