Address review comment

This commit is contained in:
Tom Hvitved
2025-03-26 08:44:03 +01:00
parent d6d3028e5a
commit b4926475d3
2 changed files with 29 additions and 15 deletions

View File

@@ -90,10 +90,10 @@ final class DataFlowCall extends TDataFlowCall {
} }
/** /**
* The position of a parameter or an argument in a function or call. * The position of a parameter in a function.
* *
* As there is a 1-to-1 correspondence between parameter positions and * In Rust there is a 1-to-1 correspondence between parameter positions and
* arguments positions in Rust we use the same type for both. * arguments positions, so we use the same underlying type for both.
*/ */
final class ParameterPosition extends TParameterPosition { final class ParameterPosition extends TParameterPosition {
/** Gets the underlying integer position, if any. */ /** Gets the underlying integer position, if any. */
@@ -126,6 +126,22 @@ final class ParameterPosition extends TParameterPosition {
} }
} }
/**
* The position of an argument in a call.
*
* In Rust there is a 1-to-1 correspondence between parameter positions and
* arguments positions, so we use the same underlying type for both.
*/
final class ArgumentPosition extends ParameterPosition {
/** Gets the argument of `call` at this position, if any. */
Expr getArgument(CallExprBase call) {
result = call.getArgList().getArg(this.getPosition())
or
this.isSelf() and
result = call.(MethodCallExpr).getReceiver()
}
}
/** Holds if `call` invokes a qualified path that resolves to a method. */ /** Holds if `call` invokes a qualified path that resolves to a method. */
private predicate callToMethod(CallExpr call) { private predicate callToMethod(CallExpr call) {
exists(Path path | exists(Path path |
@@ -432,6 +448,8 @@ private module Aliases {
class ParameterPositionAlias = ParameterPosition; class ParameterPositionAlias = ParameterPosition;
class ArgumentPositionAlias = ArgumentPosition;
class ContentAlias = Content; class ContentAlias = Content;
class ContentSetAlias = ContentSet; class ContentSetAlias = ContentSet;
@@ -550,7 +568,7 @@ module RustDataFlow implements InputSig<Location> {
class ParameterPosition = ParameterPositionAlias; class ParameterPosition = ParameterPositionAlias;
class ArgumentPosition = ParameterPosition; class ArgumentPosition = ArgumentPositionAlias;
/** /**
* Holds if the parameter position `ppos` matches the argument position * Holds if the parameter position `ppos` matches the argument position

View File

@@ -58,7 +58,9 @@ module Input implements InputSig<Location, RustDataFlow> {
string encodeParameterPosition(ParameterPosition pos) { result = pos.toString() } string encodeParameterPosition(ParameterPosition pos) { result = pos.toString() }
predicate encodeArgumentPosition = encodeParameterPosition/1; string encodeArgumentPosition(RustDataFlow::ArgumentPosition pos) {
result = encodeParameterPosition(pos)
}
string encodeContent(ContentSet cs, string arg) { string encodeContent(ContentSet cs, string arg) {
exists(Content c | cs = TSingletonContentSet(c) | exists(Content c | cs = TSingletonContentSet(c) |
@@ -143,30 +145,24 @@ private module StepsInput implements Impl::Private::StepsInputSig {
result.asCallBaseExprCfgNode().getCallExprBase() = sc.(LibraryCallable).getACall() result.asCallBaseExprCfgNode().getCallExprBase() = sc.(LibraryCallable).getACall()
} }
private Expr getArg(CallExprBase call, ParameterPosition pos) {
result = call.getArgList().getArg(pos.getPosition())
or
result = call.(MethodCallExpr).getReceiver() and pos.isSelf()
}
RustDataFlow::Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponent sc) { RustDataFlow::Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponent sc) {
sc = Impl::Private::SummaryComponent::return(_) and sc = Impl::Private::SummaryComponent::return(_) and
result.asExpr().getExpr() = source.getCall() result.asExpr().getExpr() = source.getCall()
or or
exists(CallExprBase call, Expr arg, ParameterPosition pos | exists(CallExprBase call, Expr arg, ArgumentPosition pos |
result.(RustDataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getExpr() = arg and result.(RustDataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getExpr() = arg and
sc = Impl::Private::SummaryComponent::argument(pos) and sc = Impl::Private::SummaryComponent::argument(pos) and
call = source.getCall() and call = source.getCall() and
arg = getArg(call, pos) arg = pos.getArgument(call)
) )
} }
RustDataFlow::Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { RustDataFlow::Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) {
exists(CallExprBase call, Expr arg, ParameterPosition pos | exists(CallExprBase call, Expr arg, ArgumentPosition pos |
result.asExpr().getExpr() = arg and result.asExpr().getExpr() = arg and
sc = Impl::Private::SummaryComponent::argument(pos) and sc = Impl::Private::SummaryComponent::argument(pos) and
call = sink.getCall() and call = sink.getCall() and
arg = getArg(call, pos) arg = pos.getArgument(call)
) )
} }
} }