From 3d18e3ea8fdd3d618c12a99fd4af2fc1c601fc15 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Thu, 12 Jun 2025 21:47:27 +0200 Subject: [PATCH] Rust: Use `hasImplementation` in path resolution --- .../codeql/rust/internal/PathResolution.qll | 18 ++---------------- .../PathResolutionConsistency.expected | 2 -- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 748fa0fa45da..dcbda16fcbfd 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -425,14 +425,7 @@ abstract private class AssocItemNode extends ItemNode, AssocItem { private class ConstItemNode extends AssocItemNode instanceof Const { override string getName() { result = Const.super.getName().getText() } - override predicate hasImplementation() { - super.hasBody() - or - // for trait items from library code, we do not currently know if they - // have default implementations or not, so we assume they do - not this.fromSource() and - this = any(TraitItemNode t).getAnAssocItem() - } + override predicate hasImplementation() { Const.super.hasImplementation() } override Namespace getNamespace() { result.isValue() } @@ -508,14 +501,7 @@ private class VariantItemNode extends ItemNode instanceof Variant { class FunctionItemNode extends AssocItemNode instanceof Function { override string getName() { result = Function.super.getName().getText() } - override predicate hasImplementation() { - super.hasBody() - or - // for trait items from library code, we do not currently know if they - // have default implementations or not, so we assume they do - not this.fromSource() and - this = any(TraitItemNode t).getAnAssocItem() - } + override predicate hasImplementation() { Function.super.hasImplementation() } override Namespace getNamespace() { result.isValue() } diff --git a/rust/ql/test/query-tests/security/CWE-825/CONSISTENCY/PathResolutionConsistency.expected b/rust/ql/test/query-tests/security/CWE-825/CONSISTENCY/PathResolutionConsistency.expected index 7345aedbab9a..4105369917f3 100644 --- a/rust/ql/test/query-tests/security/CWE-825/CONSISTENCY/PathResolutionConsistency.expected +++ b/rust/ql/test/query-tests/security/CWE-825/CONSISTENCY/PathResolutionConsistency.expected @@ -21,5 +21,3 @@ multiplePathResolutions | deallocation.rs:261:11:261:22 | ...::from | file://:0:0:0:0 | fn from | | deallocation.rs:261:11:261:22 | ...::from | file://:0:0:0:0 | fn from | | deallocation.rs:261:11:261:22 | ...::from | file://:0:0:0:0 | fn from | -| lifetime.rs:415:32:415:49 | ...::clone | file://:0:0:0:0 | fn clone | -| lifetime.rs:415:32:415:49 | ...::clone | file://:0:0:0:0 | fn clone |