Skip to content

Commit b492647

Browse files
committed
Address review comment
1 parent d6d3028 commit b492647

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ final class DataFlowCall extends TDataFlowCall {
9090
}
9191

9292
/**
93-
* The position of a parameter or an argument in a function or call.
93+
* The position of a parameter in a function.
9494
*
95-
* As there is a 1-to-1 correspondence between parameter positions and
96-
* arguments positions in Rust we use the same type for both.
95+
* In Rust there is a 1-to-1 correspondence between parameter positions and
96+
* arguments positions, so we use the same underlying type for both.
9797
*/
9898
final class ParameterPosition extends TParameterPosition {
9999
/** Gets the underlying integer position, if any. */
@@ -126,6 +126,22 @@ final class ParameterPosition extends TParameterPosition {
126126
}
127127
}
128128

129+
/**
130+
* The position of an argument in a call.
131+
*
132+
* In Rust there is a 1-to-1 correspondence between parameter positions and
133+
* arguments positions, so we use the same underlying type for both.
134+
*/
135+
final class ArgumentPosition extends ParameterPosition {
136+
/** Gets the argument of `call` at this position, if any. */
137+
Expr getArgument(CallExprBase call) {
138+
result = call.getArgList().getArg(this.getPosition())
139+
or
140+
this.isSelf() and
141+
result = call.(MethodCallExpr).getReceiver()
142+
}
143+
}
144+
129145
/** Holds if `call` invokes a qualified path that resolves to a method. */
130146
private predicate callToMethod(CallExpr call) {
131147
exists(Path path |
@@ -432,6 +448,8 @@ private module Aliases {
432448

433449
class ParameterPositionAlias = ParameterPosition;
434450

451+
class ArgumentPositionAlias = ArgumentPosition;
452+
435453
class ContentAlias = Content;
436454

437455
class ContentSetAlias = ContentSet;
@@ -550,7 +568,7 @@ module RustDataFlow implements InputSig<Location> {
550568

551569
class ParameterPosition = ParameterPositionAlias;
552570

553-
class ArgumentPosition = ParameterPosition;
571+
class ArgumentPosition = ArgumentPositionAlias;
554572

555573
/**
556574
* Holds if the parameter position `ppos` matches the argument position

rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ module Input implements InputSig<Location, RustDataFlow> {
5858

5959
string encodeParameterPosition(ParameterPosition pos) { result = pos.toString() }
6060

61-
predicate encodeArgumentPosition = encodeParameterPosition/1;
61+
string encodeArgumentPosition(RustDataFlow::ArgumentPosition pos) {
62+
result = encodeParameterPosition(pos)
63+
}
6264

6365
string encodeContent(ContentSet cs, string arg) {
6466
exists(Content c | cs = TSingletonContentSet(c) |
@@ -143,30 +145,24 @@ private module StepsInput implements Impl::Private::StepsInputSig {
143145
result.asCallBaseExprCfgNode().getCallExprBase() = sc.(LibraryCallable).getACall()
144146
}
145147

146-
private Expr getArg(CallExprBase call, ParameterPosition pos) {
147-
result = call.getArgList().getArg(pos.getPosition())
148-
or
149-
result = call.(MethodCallExpr).getReceiver() and pos.isSelf()
150-
}
151-
152148
RustDataFlow::Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponent sc) {
153149
sc = Impl::Private::SummaryComponent::return(_) and
154150
result.asExpr().getExpr() = source.getCall()
155151
or
156-
exists(CallExprBase call, Expr arg, ParameterPosition pos |
152+
exists(CallExprBase call, Expr arg, ArgumentPosition pos |
157153
result.(RustDataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getExpr() = arg and
158154
sc = Impl::Private::SummaryComponent::argument(pos) and
159155
call = source.getCall() and
160-
arg = getArg(call, pos)
156+
arg = pos.getArgument(call)
161157
)
162158
}
163159

164160
RustDataFlow::Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) {
165-
exists(CallExprBase call, Expr arg, ParameterPosition pos |
161+
exists(CallExprBase call, Expr arg, ArgumentPosition pos |
166162
result.asExpr().getExpr() = arg and
167163
sc = Impl::Private::SummaryComponent::argument(pos) and
168164
call = sink.getCall() and
169-
arg = getArg(call, pos)
165+
arg = pos.getArgument(call)
170166
)
171167
}
172168
}

0 commit comments

Comments
 (0)