mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
Rust: Model address-of and dereference as stores and loads
This commit is contained in:
@@ -712,6 +712,11 @@ private class CapturedVariableContent extends Content, TCapturedVariableContent
|
||||
override string toString() { result = "captured " + v }
|
||||
}
|
||||
|
||||
/** A value refered to by a reference. */
|
||||
final class ReferenceContent extends Content, TReferenceContent {
|
||||
override string toString() { result = "&ref" }
|
||||
}
|
||||
|
||||
/**
|
||||
* An element in an array.
|
||||
*/
|
||||
@@ -1040,6 +1045,13 @@ module RustDataFlow implements InputSig<Location> {
|
||||
["crate::option::Option::Some", "crate::result::Result::Ok"]
|
||||
)
|
||||
or
|
||||
exists(PrefixExprCfgNode deref |
|
||||
c instanceof ReferenceContent and
|
||||
deref.getOperatorName() = "*" and
|
||||
node1.asExpr() = deref.getExpr() and
|
||||
node2.asExpr() = deref
|
||||
)
|
||||
or
|
||||
VariableCapture::readStep(node1, c, node2)
|
||||
)
|
||||
or
|
||||
@@ -1123,6 +1135,12 @@ module RustDataFlow implements InputSig<Location> {
|
||||
node2.(PostUpdateNode).getPreUpdateNode().asExpr() = index.getBase()
|
||||
)
|
||||
or
|
||||
exists(RefExprCfgNode ref |
|
||||
c instanceof ReferenceContent and
|
||||
node1.asExpr() = ref.getExpr() and
|
||||
node2.asExpr() = ref
|
||||
)
|
||||
or
|
||||
VariableCapture::storeStep(node1, c, node2)
|
||||
)
|
||||
or
|
||||
@@ -1382,7 +1400,8 @@ private module Cached {
|
||||
e =
|
||||
[
|
||||
any(IndexExprCfgNode i).getBase(), any(FieldExprCfgNode access).getExpr(),
|
||||
any(TryExprCfgNode try).getExpr()
|
||||
any(TryExprCfgNode try).getExpr(),
|
||||
any(PrefixExprCfgNode pe | pe.getOperatorName() = "*").getExpr()
|
||||
]
|
||||
} or
|
||||
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) or
|
||||
@@ -1482,7 +1501,8 @@ private module Cached {
|
||||
TStructFieldContent(StructCanonicalPath s, string field) {
|
||||
field = s.getStruct().getFieldList().(RecordFieldList).getAField().getName().getText()
|
||||
} or
|
||||
TCapturedVariableContent(VariableCapture::CapturedVariable v)
|
||||
TCapturedVariableContent(VariableCapture::CapturedVariable v) or
|
||||
TReferenceContent()
|
||||
|
||||
cached
|
||||
newtype TContentSet = TSingletonContentSet(Content c)
|
||||
|
||||
@@ -46,6 +46,8 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
|
||||
RustDataFlow::readStep(pred, cs, succ) and
|
||||
cs.getContent() instanceof ArrayElementContent
|
||||
)
|
||||
or
|
||||
pred.asExpr() = succ.asExpr().(RefExprCfgNode).getExpr()
|
||||
)
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::summaryLocalStep(pred.(Node::FlowSummaryNode).getSummaryNode(),
|
||||
@@ -59,7 +61,10 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
|
||||
bindingset[node]
|
||||
predicate defaultImplicitTaintRead(Node::Node node, ContentSet cs) {
|
||||
exists(node) and
|
||||
cs.(SingletonContentSet).getContent() instanceof ArrayElementContent
|
||||
exists(Content c | c = cs.(SingletonContentSet).getContent() |
|
||||
c instanceof ArrayElementContent or
|
||||
c instanceof ReferenceContent
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -484,7 +484,6 @@ module Impl {
|
||||
class VariableReadAccess extends VariableAccess {
|
||||
VariableReadAccess() {
|
||||
not this instanceof VariableWriteAccess and
|
||||
not this = any(RefExpr re).getExpr() and
|
||||
not this = any(CompoundAssignmentExpr cae).getLhs()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user