Skip to content

Commit d842107

Browse files
authored
Merge pull request #20621 from hvitved/rust/static-target-addressable
Rust: Include tuple structs/variants in `CallExprBase.getStaticTarget()`
2 parents 87f32dc + 0fc2875 commit d842107

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ module Impl {
1919
* A function or method call expression. See `CallExpr` and `MethodCallExpr` for further details.
2020
*/
2121
class CallExprBase extends Generated::CallExprBase {
22-
/** Gets the static target of this call, if any. */
23-
final Function getStaticTarget() { result = TypeInference::resolveCallTarget(this) }
22+
/** Gets the static target (function or tuple struct/variant) of this call, if any. */
23+
final Addressable getStaticTarget() { result = TypeInference::resolveCallTarget(this) }
2424

2525
override Expr getArg(int index) { result = this.getArgList().getArg(index) }
2626
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ module Impl {
3838
override string toStringImpl() {
3939
result = strictconcat(int i | | this.toStringPart(i) order by i)
4040
}
41+
42+
/** Gets the static target of this method call, if any. */
43+
final Function getStaticTarget() { result = super.getStaticTarget() }
4144
}
4245
}

rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class StreamCipherInit extends Cryptography::CryptographicOperation::Range {
2626
// `cipher::KeyIvInit::new`, `cipher::KeyIvInit::new_from_slices`, `rc2::Rc2::new_with_eff_key_len` or similar.
2727
exists(CallExprBase ce, string rawAlgorithmName |
2828
ce = this.asExpr().getExpr() and
29-
ce.getStaticTarget().getName().getText() =
29+
ce.getStaticTarget().(Function).getName().getText() =
3030
["new", "new_from_slice", "new_with_eff_key_len", "new_from_slices"] and
3131
// extract the algorithm name from the type of `ce` or its receiver.
3232
exists(Type t, TypePath tp |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,9 +2505,9 @@ private module Cached {
25052505
)
25062506
}
25072507

2508-
/** Gets a function that `call` resolves to, if any. */
2508+
/** Gets an item (function or tuple struct/variant) that `call` resolves to, if any. */
25092509
cached
2510-
Function resolveCallTarget(Call call) {
2510+
Addressable resolveCallTarget(Call call) {
25112511
result = resolveMethodCallTarget(call)
25122512
or
25132513
result = resolveFunctionCallTarget(call)

rust/ql/test/library-tests/definitions/Definitions.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| main.rs:18:16:18:16 | T | main.rs:18:10:18:10 | T | path |
88
| main.rs:19:23:19:23 | T | main.rs:18:10:18:10 | T | path |
99
| main.rs:19:29:19:32 | Self | main.rs:16:5:16:24 | struct S2 | path |
10+
| main.rs:20:13:20:14 | S2 | main.rs:16:5:16:24 | struct S2 | path |
1011
| main.rs:20:16:20:16 | x | main.rs:19:20:19:20 | x | local variable |
1112
| main.rs:29:5:29:11 | println | {EXTERNAL LOCATION} | MacroRules | path |
1213
| main.rs:29:22:29:26 | value | main.rs:29:50:29:54 | value | format argument |

0 commit comments

Comments
 (0)