Skip to content

Commit 6683098

Browse files
committed
Restrict resolution
1 parent 2588def commit 6683098

File tree

7 files changed

+14
-2
lines changed

7 files changed

+14
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ module RustDataFlow implements InputSig<Location> {
814814
// A path expression, that resolves to a function, evaluates to a function
815815
// pointer. Except if the path occurs directly in a call, then it's just a
816816
// call to the function and not a function being passed as data.
817+
e.(PathExpr).hasResolvedPath() and
817818
resolvePath(e.(PathExpr).getPath()) = c.asCfgScope() and
818819
not any(CallExpr call).getFunction() = e
819820
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ private module StepsInput implements Impl::Private::StepsInputSig {
146146

147147
/** Get the callable that `expr` refers to. */
148148
private Callable getCallable(Expr expr) {
149+
expr.(PathExpr).hasResolvedPath() and
149150
result = resolvePath(expr.(PathExpr).getPath()).(Function)
150151
or
151152
result = expr.(ClosureExpr)

rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ module Impl {
1616
private import codeql.rust.internal.PathResolution as PathResolution
1717

1818
pragma[nomagic]
19-
Path getFunctionPath(CallExpr ce) { result = ce.getFunction().(PathExpr).getPath() }
19+
Path getFunctionPath(CallExpr ce) {
20+
ce.getFunction().(PathExpr).hasResolvedPath() and
21+
result = ce.getFunction().(PathExpr).getPath()
22+
}
2023

2124
pragma[nomagic]
2225
PathResolution::ItemNode getResolvedFunction(CallExpr ce) {

rust/ql/lib/codeql/rust/elements/internal/StructExprImpl.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module Impl {
3636

3737
pragma[nomagic]
3838
private PathResolution::ItemNode getResolvedPath(string name) {
39+
this.hasResolvedPath() and
3940
result = PathResolution::resolvePath(this.getPath()) and
4041
exists(this.getFieldExpr(name))
4142
}

rust/ql/lib/codeql/rust/elements/internal/StructPatImpl.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Impl {
2929

3030
pragma[nomagic]
3131
private PathResolution::ItemNode getResolvedPath(string name) {
32+
this.hasResolvedPath() and
3233
result = PathResolution::resolvePath(this.getPath()) and
3334
name = this.getStructPatFieldList().getAField().getFieldName()
3435
}

rust/ql/lib/codeql/rust/elements/internal/TupleStructPatImpl.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ module Impl {
3030

3131
pragma[nomagic]
3232
private PathResolution::ItemNode getResolvedPath(int pos) {
33+
this.hasResolvedPath() and
3334
result = PathResolution::resolvePath(this.getPath()) and
3435
exists(this.getField(pragma[only_bind_into](pos)))
3536
}
3637

3738
/**
3839
* Gets the struct matched by this pattern.
3940
*/
40-
Struct getStruct() { result = PathResolution::resolvePath(this.getPath()) }
41+
Struct getStruct() {
42+
this.hasResolvedPath() and
43+
result = PathResolution::resolvePath(this.getPath())
44+
}
4145

4246
/** Gets the tuple field that matches the `pos`th pattern of this pattern. */
4347
pragma[nomagic]

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,6 +3215,7 @@ private module Cached {
32153215
/** Gets an item (function or tuple struct/variant) that `call` resolves to, if any. */
32163216
cached
32173217
Addressable resolveCallTarget(Call call) {
3218+
call.(Resolvable).hasResolvedPath() and
32183219
result = call.(MethodResolution::MethodCall).resolveCallTarget(_, _)
32193220
or
32203221
result = call.(NonMethodResolution::NonMethodCall).resolveCallTarget()

0 commit comments

Comments
 (0)