Skip to content

Commit 647bed9

Browse files
committed
Rust: Add extensible predicate to exclude fields and block fieldless enum types
1 parent 6fcd8d1 commit 647bed9

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

@@ -36,13 +50,17 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
3650
// taint is propagated. We limit this to not apply if the type of the
3751
// operation is a small primitive type as these are often uninteresting
3852
// (for instance in the case of an injection query).
39-
RustDataFlow::readContentStep(pred, _, succ) and
40-
not exists(Struct s |
41-
s = TypeInference::inferType(succ.asExpr()).(Type::StructType).getStruct()
42-
|
43-
s instanceof Builtins::NumericType or
44-
s instanceof Builtins::Bool or
45-
s instanceof Builtins::Char
53+
exists(Content c |
54+
RustDataFlow::readContentStep(pred, c, succ) and
55+
forex(Type::Type t | t = TypeInference::inferType(succ.asExpr()) |
56+
not exists(Struct s | s = t.(Type::StructType).getStruct() |
57+
s instanceof Builtins::NumericType or
58+
s instanceof Builtins::Bool or
59+
s instanceof Builtins::Char
60+
)
61+
) and
62+
not excludedTaintStepContent(c) and
63+
not TypeInference::inferType(succ.asExpr()).(Type::EnumType).getEnum().isFieldless()
4664
)
4765
or
4866
// Let all read steps (including those from flow summaries and those that

0 commit comments

Comments
 (0)