@@ -6,7 +6,10 @@ private import rust
6
6
private import codeql.dataflow.internal.FlowSummaryImpl
7
7
private import codeql.dataflow.internal.AccessPathSyntax as AccessPath
8
8
private import codeql.rust.dataflow.internal.DataFlowImpl
9
+ private import codeql.rust.internal.PathResolution
9
10
private import codeql.rust.dataflow.FlowSummary
11
+ private import codeql.rust.dataflow.Ssa
12
+ private import codeql.rust.controlflow.CfgNodes
10
13
private import Content
11
14
12
15
module Input implements InputSig< Location , RustDataFlow > {
@@ -133,16 +136,40 @@ private module StepsInput implements Impl::Private::StepsInputSig {
133
136
result .asCallCfgNode ( ) .getCall ( ) .getStaticTarget ( ) = sc
134
137
}
135
138
136
- RustDataFlow:: Node getSourceNode ( Input:: SourceBase source , Impl:: Private:: SummaryComponent sc ) {
137
- sc = Impl:: Private:: SummaryComponent:: return ( _) and
139
+ /** Gets the argument of `source` described by `sc`, if any. */
140
+ private Expr getSourceNodeArgument ( Input:: SourceBase source , Impl:: Private:: SummaryComponent sc ) {
141
+ exists ( ArgumentPosition pos |
142
+ sc = Impl:: Private:: SummaryComponent:: argument ( pos ) and
143
+ result = pos .getArgument ( source .getCall ( ) )
144
+ )
145
+ }
146
+
147
+ /** Get the callable that `expr` refers to. */
148
+ private Callable getCallable ( Expr expr ) {
149
+ result = resolvePath ( expr .( PathExpr ) .getPath ( ) ) .( Function )
150
+ or
151
+ result = expr .( ClosureExpr )
152
+ or
153
+ // The expression is an SSA read of an assignment of a closure
154
+ exists ( Ssa:: Definition def , ExprCfgNode value |
155
+ def .getARead ( ) .getAstNode ( ) = expr and
156
+ def .getAnUltimateDefinition ( ) .( Ssa:: WriteDefinition ) .assigns ( value ) and
157
+ result = value .getExpr ( ) .( ClosureExpr )
158
+ )
159
+ }
160
+
161
+ RustDataFlow:: Node getSourceNode ( Input:: SourceBase source , Impl:: Private:: SummaryComponentStack s ) {
162
+ s .head ( ) = Impl:: Private:: SummaryComponent:: return ( _) and
138
163
result .asExpr ( ) .getExpr ( ) = source .getCall ( )
139
164
or
140
- exists ( CallExprBase call , Expr arg , ArgumentPosition pos |
141
- result .( RustDataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) .getExpr ( ) = arg and
142
- sc = Impl:: Private:: SummaryComponent:: argument ( pos ) and
143
- call = source .getCall ( ) and
144
- arg = pos .getArgument ( call )
165
+ exists ( ArgumentPosition pos , Expr arg |
166
+ s .head ( ) = Impl:: Private:: SummaryComponent:: parameter ( pos ) and
167
+ arg = getSourceNodeArgument ( source , s .tail ( ) .head ( ) ) and
168
+ result .asParameter ( ) = getCallable ( arg ) .getParam ( pos .getPosition ( ) )
145
169
)
170
+ or
171
+ result .( RustDataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) .getExpr ( ) =
172
+ getSourceNodeArgument ( source , s .head ( ) )
146
173
}
147
174
148
175
RustDataFlow:: Node getSinkNode ( Input:: SinkBase sink , Impl:: Private:: SummaryComponent sc ) {
0 commit comments