From ece2f03f0f04a56d4cd21495f754ebea33d80a47 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 27 Mar 2025 16:20:08 +0100 Subject: [PATCH] Rust: fix QL compilation errors after renames --- .../rust/controlflow/internal/ControlFlowGraphImpl.qll | 2 +- rust/ql/lib/codeql/rust/dataflow/internal/Content.qll | 4 ++-- .../ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll | 4 ++-- .../lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll | 2 +- rust/ql/lib/codeql/rust/dataflow/internal/Node.qll | 2 +- .../lib/codeql/rust/elements/internal/FieldExprImpl.qll | 4 ++-- .../codeql/rust/elements/internal/MethodCallExprImpl.qll | 2 +- rust/ql/lib/codeql/rust/elements/internal/PathImpl.qll | 4 ++-- .../lib/codeql/rust/elements/internal/PathSegmentImpl.qll | 2 +- .../codeql/rust/elements/internal/StructExprFieldImpl.qll | 8 ++++---- rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll | 2 +- .../codeql/rust/elements/internal/StructPatFieldImpl.qll | 8 ++++---- rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll | 2 +- .../lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll | 2 +- rust/ql/lib/codeql/rust/frameworks/stdlib/Clone.qll | 2 +- rust/ql/lib/codeql/rust/internal/PathResolution.qll | 4 ++-- rust/ql/lib/codeql/rust/internal/TypeInference.qll | 8 ++++---- .../rust/security/regex/RegexInjectionExtensions.qll | 2 +- 18 files changed, 32 insertions(+), 32 deletions(-) diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll index 2e954586085..900580914e2 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll @@ -329,7 +329,7 @@ module ExprTrees { } class FieldExprTree extends StandardPostOrderTree instanceof FieldExpr { - override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() } + override AstNode getChildNode(int i) { i = 0 and result = super.getContainer() } } class IfExprTree extends PostOrderTree instanceof IfExpr { diff --git a/rust/ql/lib/codeql/rust/dataflow/internal/Content.qll b/rust/ql/lib/codeql/rust/dataflow/internal/Content.qll index 97e2edccf9c..ccdf8c763ca 100644 --- a/rust/ql/lib/codeql/rust/dataflow/internal/Content.qll +++ b/rust/ql/lib/codeql/rust/dataflow/internal/Content.qll @@ -150,7 +150,7 @@ final class TuplePositionContent extends FieldContent, TTuplePositionContent { override FieldExprCfgNode getAnAccess() { // TODO: limit to tuple types - result.getNameRef().getText().toInt() = pos + result.getIdentifier().getText().toInt() = pos } override string toString() { result = "tuple." + pos.toString() } @@ -262,7 +262,7 @@ newtype TContent = TTuplePositionContent(int pos) { pos in [0 .. max([ any(TuplePat pat).getNumberOfFields(), - any(FieldExpr access).getNameRef().getText().toInt() + any(FieldExpr access).getIdentifier().getText().toInt() ] )] } or diff --git a/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll b/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll index f0f25d41264..60aa10016be 100644 --- a/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll +++ b/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll @@ -688,7 +688,7 @@ module RustDataFlow implements InputSig { node1.asPat().(RefPatCfgNode).getPat() = node2.asPat() or exists(FieldExprCfgNode access | - node1.asExpr() = access.getExpr() and + node1.asExpr() = access.getContainer() and node2.asExpr() = access and access = c.(FieldContent).getAnAccess() ) @@ -771,7 +771,7 @@ module RustDataFlow implements InputSig { exists(AssignmentExprCfgNode assignment, FieldExprCfgNode access | assignment.getLhs() = access and node1.asExpr() = assignment.getRhs() and - node2.asExpr() = access.getExpr() and + node2.asExpr() = access.getContainer() and access = c.getAnAccess() ) } diff --git a/rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll b/rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll index 7b169fb4bbf..e1cf87397b9 100644 --- a/rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll +++ b/rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll @@ -47,7 +47,7 @@ module Input implements InputSig { private class MethodCallExprNameRef extends SourceBase, SinkBase { private MethodCallExpr call; - MethodCallExprNameRef() { this = call.getNameRef() } + MethodCallExprNameRef() { this = call.getIdentifier() } override MethodCallExpr getCall() { result = call } } diff --git a/rust/ql/lib/codeql/rust/dataflow/internal/Node.qll b/rust/ql/lib/codeql/rust/dataflow/internal/Node.qll index 108d22abc34..67782f0b7e0 100644 --- a/rust/ql/lib/codeql/rust/dataflow/internal/Node.qll +++ b/rust/ql/lib/codeql/rust/dataflow/internal/Node.qll @@ -464,7 +464,7 @@ newtype TNode = e = [ any(IndexExprCfgNode i).getBase(), // - any(FieldExprCfgNode access).getExpr(), // + any(FieldExprCfgNode access).getContainer(), // any(TryExprCfgNode try).getExpr(), // any(PrefixExprCfgNode pe | pe.getOperatorName() = "*").getExpr(), // any(AwaitExprCfgNode a).getExpr(), any(MethodCallExprCfgNode mc).getReceiver(), // diff --git a/rust/ql/lib/codeql/rust/elements/internal/FieldExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/FieldExprImpl.qll index d7e2380cb77..2c037aa475a 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/FieldExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/FieldExprImpl.qll @@ -30,8 +30,8 @@ module Impl { override string toStringImpl() { exists(string abbr, string name | - abbr = this.getExpr().toAbbreviatedString() and - name = this.getNameRef().getText() and + abbr = this.getContainer().toAbbreviatedString() and + name = this.getIdentifier().getText() and if abbr = "..." then result = "... ." + name else result = abbr + "." + name ) } diff --git a/rust/ql/lib/codeql/rust/elements/internal/MethodCallExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/MethodCallExprImpl.qll index 5493c9374f2..30106d67d1a 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/MethodCallExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/MethodCallExprImpl.qll @@ -46,7 +46,7 @@ module Impl { exists(string base, string separator | base = this.getReceiver().toAbbreviatedString() and (if base = "..." then separator = " ." else separator = ".") and - result = base + separator + this.getNameRef().toStringImpl() + "(...)" + result = base + separator + this.getIdentifier().toStringImpl() + "(...)" ) } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/PathImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/PathImpl.qll index 0ff11175b2c..92c6f25fbeb 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/PathImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/PathImpl.qll @@ -39,7 +39,7 @@ module Impl { * Gets the text of this path, if it exists. */ pragma[nomagic] - string getText() { result = this.getSegment().getNameRef().getText() } + string getText() { result = this.getSegment().getIdentifier().getText() } } /** A simple identifier path. */ @@ -54,7 +54,7 @@ module Impl { not ps.hasParenthesizedArgList() and not ps.hasTypeRepr() and not ps.hasReturnTypeSyntax() and - name = ps.getNameRef().getText() + name = ps.getIdentifier().getText() ) } diff --git a/rust/ql/lib/codeql/rust/elements/internal/PathSegmentImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/PathSegmentImpl.qll index d13b42ee914..84cb37fcf61 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/PathSegmentImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/PathSegmentImpl.qll @@ -24,7 +24,7 @@ module Impl { private string toAbbreviatedStringPart(int index) { index = 0 and - if this.hasTypeRepr() then result = "<...>" else result = this.getNameRef().getText() + if this.hasTypeRepr() then result = "<...>" else result = this.getIdentifier().getText() or index = 1 and result = this.getGenericArgList().toAbbreviatedString() } diff --git a/rust/ql/lib/codeql/rust/elements/internal/StructExprFieldImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/StructExprFieldImpl.qll index 4d559594454..219ec301c85 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/StructExprFieldImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/StructExprFieldImpl.qll @@ -25,9 +25,9 @@ module Impl { override string toStringImpl() { result = concat(int i | | this.toStringPart(i) order by i) } private string toStringPart(int index) { - index = 0 and result = this.getNameRef().getText() + index = 0 and result = this.getIdentifier().getText() or - index = 1 and this.hasNameRef() and result = ": " + index = 1 and this.hasIdentifier() and result = ": " or index = 2 and result = this.getExpr().toAbbreviatedString() @@ -44,9 +44,9 @@ module Impl { * ``` */ string getFieldName() { - result = this.getNameRef().getText() + result = this.getIdentifier().getText() or - not this.hasNameRef() and + not this.hasIdentifier() and result = this.getExpr().(PathExpr).getPath().(PathImpl::IdentPath).getName() } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll index 1693f1b989b..9f8888d3b6e 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll @@ -25,7 +25,7 @@ module Impl { /** Gets the record field named `name`, if any. */ pragma[nomagic] StructField getStructField(string name) { - result = this.getFieldList().(RecordFieldList).getAField() and + result = this.getFieldList().(StructFieldList).getAField() and result.getName().getText() = name } diff --git a/rust/ql/lib/codeql/rust/elements/internal/StructPatFieldImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/StructPatFieldImpl.qll index 995188e9452..d569c4a0016 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/StructPatFieldImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/StructPatFieldImpl.qll @@ -24,9 +24,9 @@ module Impl { override string toStringImpl() { result = concat(int i | | this.toStringPart(i) order by i) } private string toStringPart(int index) { - index = 0 and result = this.getNameRef().getText() + index = 0 and result = this.getIdentifier().getText() or - index = 1 and this.hasNameRef() and result = ": " + index = 1 and this.hasIdentifier() and result = ": " or index = 2 and result = this.getPat().toAbbreviatedString() @@ -43,9 +43,9 @@ module Impl { * ``` */ string getFieldName() { - result = this.getNameRef().getText() + result = this.getIdentifier().getText() or - not this.hasNameRef() and + not this.hasIdentifier() and result = this.getPat().(IdentPat).getName().getText() } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll index ad46ee68848..8af1d05edba 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll @@ -25,7 +25,7 @@ module Impl { /** Gets the record field named `name`, if any. */ pragma[nomagic] StructField getStructField(string name) { - result = this.getFieldList().(RecordFieldList).getAField() and + result = this.getFieldList().(StructFieldList).getAField() and result.getName().getText() = name } diff --git a/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll b/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll index c043cbf6033..70b92a3f7ea 100644 --- a/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll +++ b/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll @@ -39,7 +39,7 @@ class StreamCipherInit extends Cryptography::CryptographicOperation::Range { .(PathTypeRepr) .getPath() .getSegment() - .getNameRef() + .getIdentifier() .getText() ) and algorithmName = simplifyAlgorithmName(rawAlgorithmName) diff --git a/rust/ql/lib/codeql/rust/frameworks/stdlib/Clone.qll b/rust/ql/lib/codeql/rust/frameworks/stdlib/Clone.qll index 456da7bdde0..0798343837e 100644 --- a/rust/ql/lib/codeql/rust/frameworks/stdlib/Clone.qll +++ b/rust/ql/lib/codeql/rust/frameworks/stdlib/Clone.qll @@ -9,7 +9,7 @@ final class CloneCallable extends SummarizedCallable::Range { // NOTE: The function target may not exist in the database, so we base this // on method calls. exists(MethodCallExpr c | - c.getNameRef().getText() = "clone" and + c.getIdentifier().getText() = "clone" and c.getArgList().getNumberOfArgs() = 0 and this = c.getResolvedCrateOrigin() + "::_::" + c.getResolvedPath() ) diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index bd98bf6ec03..74a07ab890e 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -312,7 +312,7 @@ private class VariantItemNode extends ItemNode instanceof Variant { override string getName() { result = Variant.super.getName().getText() } override Namespace getNamespace() { - if super.getFieldList() instanceof RecordFieldList then result.isType() else result.isValue() + if super.getFieldList() instanceof StructFieldList then result.isType() else result.isValue() } override TypeParam getTypeParam(int i) { @@ -471,7 +471,7 @@ private class StructItemNode extends ItemNode instanceof Struct { override Namespace getNamespace() { result.isType() // the struct itself or - not super.getFieldList() instanceof RecordFieldList and + not super.getFieldList() instanceof StructFieldList and result.isValue() // the constructor } diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index 1e468edc5a7..5c59cee8a17 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -764,7 +764,7 @@ private module FieldExprMatchingInput implements MatchingInputSig { Type getTypeArgument(TypeArgumentPosition apos, TypePath path) { none() } AstNode getNodeAt(AccessPosition apos) { - result = this.getExpr() and + result = this.getContainer() and apos.isSelf() or result = this and @@ -903,7 +903,7 @@ private module Cached { pragma[nomagic] private Type getMethodCallExprLookupType(MethodCallExpr mce, string name) { result = getLookupType(mce.getReceiver()) and - name = mce.getNameRef().getText() + name = mce.getIdentifier().getText() } /** @@ -916,8 +916,8 @@ private module Cached { pragma[nomagic] private Type getFieldExprLookupType(FieldExpr fe, string name) { - result = getLookupType(fe.getExpr()) and - name = fe.getNameRef().getText() + result = getLookupType(fe.getContainer()) and + name = fe.getIdentifier().getText() } /** diff --git a/rust/ql/lib/codeql/rust/security/regex/RegexInjectionExtensions.qll b/rust/ql/lib/codeql/rust/security/regex/RegexInjectionExtensions.qll index ec0dfa56e1d..f1e4060a5cf 100644 --- a/rust/ql/lib/codeql/rust/security/regex/RegexInjectionExtensions.qll +++ b/rust/ql/lib/codeql/rust/security/regex/RegexInjectionExtensions.qll @@ -64,7 +64,7 @@ private class RegexInjectionDefaultBarrier extends RegexInjectionBarrier { .(PathExpr) .getPath() .getSegment() - .getNameRef() + .getIdentifier() .getText() = "escape" } }