File tree Expand file tree Collapse file tree 13 files changed +36
-22
lines changed
test/library-tests/modules Expand file tree Collapse file tree 13 files changed +36
-22
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ private import codeql.ruby.AST
10
10
private import codeql.ruby.DataFlow
11
11
private import codeql.ruby.typetracking.TypeTracker
12
12
private import codeql.ruby.typetracking.TypeTrackerSpecific as TypeTrackerSpecific
13
- private import codeql.ruby.ast.internal.Module
14
13
private import codeql.ruby.controlflow.CfgNodes
15
14
private import codeql.ruby.dataflow.internal.DataFlowPrivate as DataFlowPrivate
16
15
private import codeql.ruby.dataflow.internal.DataFlowDispatch as DataFlowDispatch
@@ -482,7 +481,7 @@ module API {
482
481
MkDef ( DataFlow:: Node nd ) { isDef ( nd ) }
483
482
484
483
private string resolveTopLevel ( ConstantReadAccess read ) {
485
- TResolved ( result ) = resolveConstantReadAccess ( read ) and
484
+ result = read . getModule ( ) . getQualifiedName ( ) and
486
485
not result .matches ( "%::%" )
487
486
}
488
487
@@ -706,7 +705,7 @@ module API {
706
705
exists ( ClassDeclaration c , DataFlow:: Node a , DataFlow:: Node b |
707
706
use ( pred , a ) and
708
707
use ( succ , b ) and
709
- resolveConstant ( b .asExpr ( ) .getExpr ( ) ) = resolveConstantWriteAccess ( c ) and
708
+ b .asExpr ( ) .getExpr ( ) . ( ConstantReadAccess ) . getAQualifiedName ( ) = c . getAQualifiedName ( ) and
710
709
pragma [ only_bind_into ] ( c ) .getSuperclassExpr ( ) = a .asExpr ( ) .getExpr ( ) and
711
710
lbl = Label:: subclass ( )
712
711
)
Original file line number Diff line number Diff line change @@ -293,6 +293,15 @@ class ConstantReadAccess extends ConstantAccess {
293
293
*/
294
294
Expr getValue ( ) { result = getConstantReadAccessValue ( this ) }
295
295
296
+ /**
297
+ * Gets a fully qualified name for this constant read, based on the context in
298
+ * which it occurs.
299
+ */
300
+ string getAQualifiedName ( ) { result = resolveConstant ( this ) }
301
+
302
+ /** Gets the module that this read access resolves to, if any. */
303
+ Module getModule ( ) { result = resolveConstantReadAccess ( this ) }
304
+
296
305
final override string getAPrimaryQlClass ( ) { result = "ConstantReadAccess" }
297
306
}
298
307
@@ -354,7 +363,7 @@ class ConstantWriteAccess extends ConstantAccess {
354
363
* constants up the namespace chain, the fully qualified name of a nested
355
364
* constant can be ambiguous from just statically looking at the AST.
356
365
*/
357
- string getAQualifiedName ( ) { result = resolveConstantWriteAccess ( this ) }
366
+ string getAQualifiedName ( ) { result = resolveConstantWrite ( this ) }
358
367
359
368
/**
360
369
* Gets a qualified name for this constant. Deprecated in favor of
Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ class Module extends TModule {
34
34
exists ( Namespace n | this = TUnresolved ( n ) and result = "...::" + n .toString ( ) )
35
35
}
36
36
37
+ /**
38
+ * Gets the qualified name of this module, if any.
39
+ *
40
+ * Only modules that can be resolved will have a qualified name.
41
+ */
42
+ final string getQualifiedName ( ) { this = TResolved ( result ) }
43
+
37
44
/** Gets the location of this module. */
38
45
Location getLocation ( ) {
39
46
exists ( Namespace n | this = TUnresolved ( n ) and result = n .getLocation ( ) )
Original file line number Diff line number Diff line change @@ -135,6 +135,9 @@ private module Cached {
135
135
)
136
136
}
137
137
138
+ cached
139
+ string resolveConstantWrite ( ConstantWriteAccess c ) { result = resolveConstantWriteAccess ( c ) }
140
+
138
141
cached
139
142
Method lookupMethod ( Module m , string name ) { TMethod ( result ) = lookupMethodOrConst ( m , name ) }
140
143
@@ -472,7 +475,7 @@ private module ResolveImpl {
472
475
}
473
476
}
474
477
475
- import ResolveImpl
478
+ private import ResolveImpl
476
479
477
480
/**
478
481
* A variant of AstNode::getEnclosingModule that excludes
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ private import codeql.ruby.Concepts
7
7
private import codeql.ruby.controlflow.CfgNodes
8
8
private import codeql.ruby.DataFlow
9
9
private import codeql.ruby.dataflow.RemoteFlowSources
10
- private import codeql.ruby.ast.internal.Module
11
10
private import codeql.ruby.ApiGraphs
12
11
private import ActionView
13
12
private import codeql.ruby.frameworks.ActionDispatch
@@ -101,7 +100,7 @@ private predicate isRoute(
101
100
ActionDispatch:: Routing:: Route route , string name , ActionControllerControllerClass controllerClass
102
101
) {
103
102
route .getController ( ) + "_controller" =
104
- ActionDispatch:: Routing:: underscore ( namespaceDeclaration ( controllerClass ) ) and
103
+ ActionDispatch:: Routing:: underscore ( controllerClass . getAQualifiedName ( ) ) and
105
104
name = route .getAction ( )
106
105
}
107
106
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ private import codeql.ruby.Concepts
8
8
private import codeql.ruby.controlflow.CfgNodes
9
9
private import codeql.ruby.DataFlow
10
10
private import codeql.ruby.dataflow.RemoteFlowSources
11
- private import codeql.ruby.ast.internal.Module
12
11
private import ActionController
13
12
14
13
/**
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ private import codeql.ruby.controlflow.CfgNodes
8
8
private import codeql.ruby.DataFlow
9
9
private import codeql.ruby.dataflow.internal.DataFlowDispatch
10
10
private import codeql.ruby.dataflow.internal.DataFlowPrivate
11
- private import codeql.ruby.ast.internal.Module
12
11
private import codeql.ruby.ApiGraphs
13
12
private import codeql.ruby.frameworks.Stdlib
14
13
private import codeql.ruby.frameworks.Core
@@ -95,7 +94,7 @@ class ActiveRecordModelClassMethodCall extends MethodCall {
95
94
96
95
ActiveRecordModelClassMethodCall ( ) {
97
96
// e.g. Foo.where(...)
98
- recvCls .getModule ( ) = resolveConstantReadAccess ( this .getReceiver ( ) )
97
+ recvCls .getModule ( ) = this .getReceiver ( ) . ( ConstantReadAccess ) . getModule ( )
99
98
or
100
99
// e.g. Foo.joins(:bars).where(...)
101
100
recvCls = this .getReceiver ( ) .( ActiveRecordModelClassMethodCall ) .getReceiverClass ( )
@@ -282,7 +281,7 @@ private class ActiveRecordModelFinderCall extends ActiveRecordModelInstantiation
282
281
recv = getUltimateReceiver ( call ) and
283
282
(
284
283
// The receiver refers to an `ActiveRecordModelClass` by name
285
- resolveConstant ( recv ) = cls .getAQualifiedName ( )
284
+ recv . ( ConstantReadAccess ) . getAQualifiedName ( ) = cls .getAQualifiedName ( )
286
285
or
287
286
// The receiver is self, and the call is within a singleton method of
288
287
// the `ActiveRecordModelClass`
Original file line number Diff line number Diff line change 6
6
private import codeql.ruby.AST
7
7
private import codeql.ruby.Concepts
8
8
private import codeql.ruby.controlflow.CfgNodes
9
- private import codeql.ruby.ast.internal.Module
10
9
private import codeql.ruby.DataFlow
11
10
private import codeql.ruby.ApiGraphs
12
11
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ private import codeql.ruby.Concepts
7
7
private import codeql.ruby.controlflow.CfgNodes
8
8
private import codeql.ruby.DataFlow
9
9
private import codeql.ruby.dataflow.RemoteFlowSources
10
- private import codeql.ruby.ast.internal.Module
11
10
private import codeql.ruby.ApiGraphs
12
11
13
12
private API:: Node graphQlSchema ( ) { result = API:: getTopLevelMember ( "GraphQL" ) .getMember ( "Schema" ) }
@@ -233,7 +232,7 @@ private class GraphqlSchemaObjectClassMethodCall extends MethodCall {
233
232
234
233
GraphqlSchemaObjectClassMethodCall ( ) {
235
234
// e.g. Foo.some_method(...)
236
- recvCls .getModule ( ) = resolveConstantReadAccess ( this .getReceiver ( ) )
235
+ recvCls .getModule ( ) = this .getReceiver ( ) . ( ConstantReadAccess ) . getModule ( )
237
236
or
238
237
// e.g. self.some_method(...) within a graphql Object or Interface
239
238
this .getReceiver ( ) instanceof SelfVariableAccess and
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ private import codeql.ruby.frameworks.ActionController
9
9
private import codeql.ruby.frameworks.ActionView
10
10
private import codeql.ruby.frameworks.ActiveRecord
11
11
private import codeql.ruby.frameworks.ActiveStorage
12
- private import codeql.ruby.ast.internal.Module
13
12
private import codeql.ruby.ApiGraphs
14
13
private import codeql.ruby.security.OpenSSL
15
14
@@ -29,7 +28,7 @@ private class RailtieClass extends ClassDeclaration {
29
28
RailtieClass ( ) {
30
29
this .getSuperclassExpr ( ) instanceof RailtieClassAccess or
31
30
exists ( RailtieClass other |
32
- other .getModule ( ) = resolveConstantReadAccess ( this .getSuperclassExpr ( ) )
31
+ other .getModule ( ) = this .getSuperclassExpr ( ) . ( ConstantReadAccess ) . getModule ( )
33
32
)
34
33
}
35
34
}
@@ -41,7 +40,7 @@ private DataFlow::CallNode getAConfigureCallNode() {
41
40
// `Rails::Application.configure`
42
41
exists ( ConstantReadAccess read , RailtieClass cls |
43
42
read = result .getReceiver ( ) .asExpr ( ) .getExpr ( ) and
44
- resolveConstantReadAccess ( read ) = cls .getModule ( ) and
43
+ read . getModule ( ) = cls .getModule ( ) and
45
44
result .asExpr ( ) .getExpr ( ) .( MethodCall ) .getMethodName ( ) = "configure"
46
45
)
47
46
}
You can’t perform that action at this time.
0 commit comments