@@ -11,26 +11,32 @@ private import codeql.rust.dataflow.internal.TaintTrackingImpl
11
11
private import codeql.mad.modelgenerator.internal.ModelGeneratorImpl
12
12
private import codeql.rust.dataflow.internal.FlowSummaryImpl as FlowSummary
13
13
14
- private predicate relevant ( Function api ) {
15
- // Only include functions that have a resolved path.
16
- api .hasCrateOrigin ( ) and
17
- api .hasExtendedCanonicalPath ( ) and
18
- // A canonical path can contain `;` as the syntax for array types use `;`. For
19
- // instance `<[Foo; 1] as Bar>::baz`. This does not work with the shared model
20
- // generator and it is not clear if this will also be the case when we move to
21
- // QL created canoonical paths, so for now we just exclude functions with
22
- // `;`s.
23
- not exists ( api .getExtendedCanonicalPath ( ) .indexOf ( ";" ) ) and
24
- (
25
- // This excludes closures (these are not exported API endpoints) and
26
- // functions without a `pub` visibility. A function can be `pub` without
27
- // ultimately being exported by a crate, so this is an overapproximation.
28
- api .hasVisibility ( )
29
- or
30
- // If a method implements a public trait it is exposed through the trait.
31
- // We overapproximate this by including all trait method implementations.
32
- exists ( Impl impl | impl .hasTrait ( ) and impl .getAssocItemList ( ) .getAssocItem ( _) = api )
33
- )
14
+ private newtype TCallable =
15
+ TFunction ( Function api , string path ) {
16
+ path = api .getCanonicalPath ( ) and
17
+ (
18
+ // This excludes closures (these are not exported API endpoints) and
19
+ // functions without a `pub` visibility. A function can be `pub` without
20
+ // ultimately being exported by a crate, so this is an overapproximation.
21
+ api .hasVisibility ( )
22
+ or
23
+ // If a method implements a public trait it is exposed through the trait.
24
+ // We overapproximate this by including all trait method implementations.
25
+ exists ( Impl impl | impl .hasTrait ( ) and impl .getAssocItemList ( ) .getAssocItem ( _) = api )
26
+ )
27
+ }
28
+
29
+ private class QualifiedCallable extends TCallable {
30
+ Function api ;
31
+ string path ;
32
+
33
+ QualifiedCallable ( ) { this = TFunction ( api , path ) }
34
+
35
+ string toString ( ) { result = path }
36
+
37
+ Function asFunction ( ) { result = api }
38
+
39
+ string getCanonicalPath ( ) { result = path }
34
40
}
35
41
36
42
module ModelGeneratorCommonInput implements
@@ -41,14 +47,14 @@ module ModelGeneratorCommonInput implements
41
47
42
48
class Parameter = R:: ParamBase ;
43
49
44
- class Callable = R :: Callable ;
50
+ class Callable = QualifiedCallable ;
45
51
46
52
class NodeExtended extends DataFlow:: Node {
47
53
Type getType ( ) { any ( ) }
48
54
}
49
55
50
- Callable getEnclosingCallable ( NodeExtended node ) {
51
- result = node .( Node:: Node ) .getEnclosingCallable ( ) .asCfgScope ( )
56
+ QualifiedCallable getEnclosingCallable ( NodeExtended node ) {
57
+ result . asFunction ( ) = node .( Node:: Node ) .getEnclosingCallable ( ) .asCfgScope ( )
52
58
}
53
59
54
60
predicate isRelevantType ( Type t ) { any ( ) }
@@ -73,19 +79,19 @@ module ModelGeneratorCommonInput implements
73
79
}
74
80
75
81
bindingset [ c]
76
- string paramReturnNodeAsApproximateOutput ( Callable c , DataFlowImpl:: ParameterPosition pos ) {
82
+ string paramReturnNodeAsApproximateOutput ( QualifiedCallable c , DataFlowImpl:: ParameterPosition pos ) {
77
83
result = paramReturnNodeAsExactOutput ( c , pos )
78
84
}
79
85
80
86
bindingset [ c]
81
- string paramReturnNodeAsExactOutput ( Callable c , DataFlowImpl:: ParameterPosition pos ) {
82
- result = parameterExactAccess ( c .getParam ( pos .getPosition ( ) ) )
87
+ string paramReturnNodeAsExactOutput ( QualifiedCallable c , DataFlowImpl:: ParameterPosition pos ) {
88
+ result = parameterExactAccess ( c .asFunction ( ) . getParam ( pos .getPosition ( ) ) )
83
89
or
84
90
pos .isSelf ( ) and result = qualifierString ( )
85
91
}
86
92
87
- Callable returnNodeEnclosingCallable ( DataFlow:: Node ret ) {
88
- result = ret .( Node:: Node ) .getEnclosingCallable ( ) .asCfgScope ( )
93
+ QualifiedCallable returnNodeEnclosingCallable ( DataFlow:: Node ret ) {
94
+ result . asFunction ( ) = ret .( Node:: Node ) .getEnclosingCallable ( ) .asCfgScope ( )
89
95
}
90
96
91
97
predicate isOwnInstanceAccessNode ( DataFlowImpl:: RustDataFlow:: ReturnNode node ) {
@@ -99,10 +105,8 @@ module ModelGeneratorCommonInput implements
99
105
c .( SingletonContentSet ) .getContent ( ) instanceof ElementContent
100
106
}
101
107
102
- string partialModelRow ( Callable api , int i ) {
103
- i = 0 and result = api .( Function ) .getCrateOrigin ( ) // crate
104
- or
105
- i = 1 and result = api .( Function ) .getExtendedCanonicalPath ( ) // name
108
+ string partialModelRow ( QualifiedCallable api , int i ) {
109
+ i = 0 and result = min ( string path | path = api .( Function ) .getCanonicalPath ( ) | path )
106
110
}
107
111
108
112
string partialNeutralModelRow ( Callable api , int i ) { result = partialModelRow ( api , i ) }
0 commit comments