File tree Expand file tree Collapse file tree 2 files changed +19
-15
lines changed
ruby/ql/lib/codeql/ruby/ast Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -224,21 +224,7 @@ class ConstantReadAccess extends ConstantAccess {
224224 *
225225 * the value being read at `M::CONST` is `"const"`.
226226 */
227- Expr getValue ( ) {
228- not exists ( this .getScopeExpr ( ) ) and
229- result = lookupConst ( this .getEnclosingModule + ( ) .getModule ( ) , this .getName ( ) ) and
230- // For now, we restrict the scope of top-level declarations to their file.
231- // This may remove some plausible targets, but also removes a lot of
232- // implausible targets
233- if result .getEnclosingModule ( ) instanceof Toplevel
234- then result .getFile ( ) = this .getFile ( )
235- else any ( )
236- or
237- this .hasGlobalScope ( ) and
238- result = lookupConst ( TResolved ( "Object" ) , this .getName ( ) )
239- or
240- result = lookupConst ( resolveConstantReadAccess ( this .getScopeExpr ( ) ) , this .getName ( ) )
241- }
227+ Expr getValue ( ) { result = getConstantReadAccessValue ( this ) }
242228
243229 final override string getAPrimaryQlClass ( ) { result = "ConstantReadAccess" }
244230}
Original file line number Diff line number Diff line change 11private import codeql.ruby.AST
22private import codeql.ruby.ast.internal.Literal
3+ private import codeql.ruby.ast.internal.Module
34private import codeql.ruby.controlflow.CfgNodes
45private import codeql.ruby.dataflow.SSA
56private import ExprNodes
@@ -441,6 +442,23 @@ private module Cached {
441442 result .isNil ( ) and
442443 isNilExpr ( e )
443444 }
445+
446+ cached
447+ Expr getConstantReadAccessValue ( ConstantReadAccess read ) {
448+ not exists ( read .getScopeExpr ( ) ) and
449+ result = lookupConst ( read .getEnclosingModule + ( ) .getModule ( ) , read .getName ( ) ) and
450+ // For now, we restrict the scope of top-level declarations to their file.
451+ // This may remove some plausible targets, but also removes a lot of
452+ // implausible targets
453+ if result .getEnclosingModule ( ) instanceof Toplevel
454+ then result .getFile ( ) = read .getFile ( )
455+ else any ( )
456+ or
457+ read .hasGlobalScope ( ) and
458+ result = lookupConst ( TResolved ( "Object" ) , read .getName ( ) )
459+ or
460+ result = lookupConst ( resolveConstantReadAccess ( read .getScopeExpr ( ) ) , read .getName ( ) )
461+ }
444462}
445463
446464import Cached
You can’t perform that action at this time.
0 commit comments