Skip to content

Commit a96a5fc

Browse files
committed
Rust: Address PR comments
1 parent 4dbfda5 commit a96a5fc

File tree

4 files changed

+68
-67
lines changed

4 files changed

+68
-67
lines changed

rust/ql/lib/codeql/rust/dataflow/DataFlow.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ module DataFlow {
2626

2727
final class Content = Content::Content;
2828

29+
final class FieldContent = Content::FieldContent;
30+
31+
final class TuplePositionContent = Content::TuplePositionContent;
32+
33+
final class TupleFieldContent = Content::TupleFieldContent;
34+
35+
final class RecordFieldContent = Content::RecordFieldContent;
36+
37+
final class ReferenceContent = Content::ReferenceContent;
38+
39+
final class ElementContent = Content::ElementContent;
40+
41+
final class FutureContent = Content::FutureContent;
42+
2943
final class ContentSet = Content::ContentSet;
3044

3145
/**

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -209,32 +209,26 @@ final class SingletonContentSet extends ContentSet, TSingletonContentSet {
209209
override Content getAReadContent() { result = c }
210210
}
211211

212-
/** A collection of cached types and predicates to be evaluated in the same stage. */
213-
cached
214-
private module Cached {
215-
private import codeql.rust.internal.CachedStages
216-
217-
cached
218-
newtype TContent =
219-
TTupleFieldContent(TupleField field) { Stages::DataFlowStage::ref() } or
220-
TRecordFieldContent(RecordField field) or
221-
// TODO: Remove once library types are extracted
222-
TVariantInLibTupleFieldContent(VariantInLib::VariantInLib v, int pos) { pos = v.getAPosition() } or
223-
TElementContent() or
224-
TFutureContent() or
225-
TTuplePositionContent(int pos) {
226-
pos in [0 .. max([
227-
any(TuplePat pat).getNumberOfFields(),
228-
any(FieldExpr access).getNameRef().getText().toInt()
229-
]
230-
)]
231-
} or
232-
TFunctionCallReturnContent() or
233-
TFunctionCallArgumentContent(int pos) {
234-
pos in [0 .. any(CallExpr c).getArgList().getNumberOfArgs() - 1]
235-
} or
236-
TCapturedVariableContent(VariableCapture::CapturedVariable v) or
237-
TReferenceContent()
238-
}
212+
private import codeql.rust.internal.CachedStages
239213

240-
import Cached
214+
cached
215+
newtype TContent =
216+
TTupleFieldContent(TupleField field) { Stages::DataFlowStage::ref() } or
217+
TRecordFieldContent(RecordField field) or
218+
// TODO: Remove once library types are extracted
219+
TVariantInLibTupleFieldContent(VariantInLib::VariantInLib v, int pos) { pos = v.getAPosition() } or
220+
TElementContent() or
221+
TFutureContent() or
222+
TTuplePositionContent(int pos) {
223+
pos in [0 .. max([
224+
any(TuplePat pat).getNumberOfFields(),
225+
any(FieldExpr access).getNameRef().getText().toInt()
226+
]
227+
)]
228+
} or
229+
TFunctionCallReturnContent() or
230+
TFunctionCallArgumentContent(int pos) {
231+
pos in [0 .. any(CallExpr c).getArgList().getNumberOfArgs() - 1]
232+
} or
233+
TCapturedVariableContent(VariableCapture::CapturedVariable v) or
234+
TReferenceContent()

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

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -446,41 +446,35 @@ private class CapturePostUpdateNode extends PostUpdateNode, CaptureNode {
446446

447447
final class CastNode = NaNode;
448448

449-
/** A collection of cached types and predicates to be evaluated in the same stage. */
450-
cached
451-
private module Cached {
452-
private import codeql.rust.internal.CachedStages
453-
454-
cached
455-
newtype TNode =
456-
TExprNode(ExprCfgNode n) { Stages::DataFlowStage::ref() } or
457-
TSourceParameterNode(ParamBaseCfgNode p) or
458-
TPatNode(PatCfgNode p) or
459-
TNameNode(NameCfgNode n) { n.getName() = any(Variable v).getName() } or
460-
TExprPostUpdateNode(ExprCfgNode e) {
461-
isArgumentForCall(e, _, _)
462-
or
463-
lambdaCallExpr(_, _, e)
464-
or
465-
lambdaCreationExpr(e.getExpr(), _)
466-
or
467-
// Whenever `&mut e` has a post-update node we also create one for `e`.
468-
// E.g., for `e` in `f(..., &mut e, ...)` or `*(&mut e) = ...`.
469-
e = any(RefExprCfgNode ref | ref.isMut() and exists(TExprPostUpdateNode(ref))).getExpr()
470-
or
471-
e =
472-
[
473-
any(IndexExprCfgNode i).getBase(), any(FieldExprCfgNode access).getExpr(),
474-
any(TryExprCfgNode try).getExpr(),
475-
any(PrefixExprCfgNode pe | pe.getOperatorName() = "*").getExpr(),
476-
any(AwaitExprCfgNode a).getExpr(), any(MethodCallExprCfgNode mc).getReceiver()
477-
]
478-
} or
479-
TReceiverNode(MethodCallExprCfgNode mc, Boolean isPost) or
480-
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) or
481-
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) or
482-
TClosureSelfReferenceNode(CfgScope c) { lambdaCreationExpr(c, _) } or
483-
TCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn)
484-
}
449+
private import codeql.rust.internal.CachedStages
485450

486-
import Cached
451+
cached
452+
newtype TNode =
453+
TExprNode(ExprCfgNode n) { Stages::DataFlowStage::ref() } or
454+
TSourceParameterNode(ParamBaseCfgNode p) or
455+
TPatNode(PatCfgNode p) or
456+
TNameNode(NameCfgNode n) { n.getName() = any(Variable v).getName() } or
457+
TExprPostUpdateNode(ExprCfgNode e) {
458+
isArgumentForCall(e, _, _)
459+
or
460+
lambdaCallExpr(_, _, e)
461+
or
462+
lambdaCreationExpr(e.getExpr(), _)
463+
or
464+
// Whenever `&mut e` has a post-update node we also create one for `e`.
465+
// E.g., for `e` in `f(..., &mut e, ...)` or `*(&mut e) = ...`.
466+
e = any(RefExprCfgNode ref | ref.isMut() and exists(TExprPostUpdateNode(ref))).getExpr()
467+
or
468+
e =
469+
[
470+
any(IndexExprCfgNode i).getBase(), any(FieldExprCfgNode access).getExpr(),
471+
any(TryExprCfgNode try).getExpr(),
472+
any(PrefixExprCfgNode pe | pe.getOperatorName() = "*").getExpr(),
473+
any(AwaitExprCfgNode a).getExpr(), any(MethodCallExprCfgNode mc).getReceiver()
474+
]
475+
} or
476+
TReceiverNode(MethodCallExprCfgNode mc, Boolean isPost) or
477+
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) or
478+
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) or
479+
TClosureSelfReferenceNode(CfgScope c) { lambdaCreationExpr(c, _) } or
480+
TCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn)

rust/ql/src/queries/security/CWE-312/CleartextLogging.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import rust
1717
import codeql.rust.security.CleartextLoggingExtensions
1818
import codeql.rust.dataflow.DataFlow
1919
import codeql.rust.dataflow.TaintTracking
20-
import codeql.rust.dataflow.internal.Content
2120

2221
/**
2322
* A taint-tracking configuration for cleartext logging vulnerabilities.
@@ -44,7 +43,7 @@ module CleartextLoggingConfig implements DataFlow::ConfigSig {
4443
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
4544
// flow out from tuple content at sinks.
4645
isSink(node) and
47-
c.getAReadContent() instanceof TuplePositionContent
46+
c.getAReadContent() instanceof DataFlow::TuplePositionContent
4847
}
4948
}
5049

0 commit comments

Comments
 (0)