Skip to content

Commit 22d39b4

Browse files
committed
Rust: Add extensible predicate to exclude fields and block fieldless enum types
1 parent a8d580f commit 22d39b4

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ private import codeql.rust.internal.TypeInference as TypeInference
1111
private import codeql.rust.internal.Type as Type
1212
private import codeql.rust.frameworks.stdlib.Builtins as Builtins
1313

14+
/**
15+
* Holds if the field `field` should, by default, be excluded from taint steps.
16+
* The syntax used to denote the field is the same as for `Field` in
17+
* models-as-data.
18+
*/
19+
extensible predicate excludeFieldTaintStep(string field);
20+
21+
private predicate excludedTaintStepContent(Content c) {
22+
exists(string arg | excludeFieldTaintStep(arg) |
23+
FlowSummaryImpl::encodeContentStructField(c, arg) or
24+
FlowSummaryImpl::encodeContentTupleField(c, arg)
25+
)
26+
}
27+
1428
module RustTaintTracking implements InputSig<Location, RustDataFlow> {
1529
predicate defaultTaintSanitizer(DataFlow::Node node) { none() }
1630

@@ -48,13 +62,17 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
4862
// taint is propagated. We limit this to not apply if the type of the
4963
// operation is a small primitive type as these are often uninteresting
5064
// (for instance in the case of an injection query).
51-
RustDataFlow::readContentStep(pred, _, succ) and
52-
not exists(Struct s |
53-
s = TypeInference::inferType(succ.asExpr()).(Type::StructType).getStruct()
54-
|
55-
s instanceof Builtins::NumericType or
56-
s instanceof Builtins::Bool or
57-
s instanceof Builtins::Char
65+
exists(Content c |
66+
RustDataFlow::readContentStep(pred, c, succ) and
67+
forex(Type::Type t | t = TypeInference::inferType(succ.asExpr()) |
68+
not exists(Struct s | s = t.(Type::StructType).getStruct() |
69+
s instanceof Builtins::NumericType or
70+
s instanceof Builtins::Bool or
71+
s instanceof Builtins::Char
72+
)
73+
) and
74+
not excludedTaintStepContent(c) and
75+
not TypeInference::inferType(succ.asExpr()).(Type::EnumType).getEnum().isFieldless()
5876
)
5977
or
6078
// Let all read steps (including those from flow summaries and those that

0 commit comments

Comments
 (0)