Skip to content

Commit e66a251

Browse files
committed
WIP
1 parent 0ca72b5 commit e66a251

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
4949
// operation is a small primitive type as these are often uninteresting
5050
// (for instance in the case of an injection query).
5151
RustDataFlow::readContentStep(pred, _, succ) and
52+
exists(TypeInference::inferType(succ.asExpr())) and
5253
not exists(Struct s |
5354
s = TypeInference::inferType(succ.asExpr()).(Type::StructType).getStruct()
5455
|
5556
s instanceof Builtins::NumericType or
5657
s instanceof Builtins::Bool or
5758
s instanceof Builtins::Char
58-
)
59+
) and
60+
not TypeInference::inferType(succ.asExpr()).(Type::EnumType).getEnum().isFieldless() and
61+
not succ.asExpr().(FieldExpr).getIdentifier().getText() = "start" and
62+
not succ.asExpr().(FieldExpr).getIdentifier().getText() = "end"
5963
or
6064
// Let all read steps (including those from flow summaries and those that
6165
// result in small primitive types) give rise to taint steps.

rust/ql/lib/codeql/rust/elements/internal/EnumImpl.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,14 @@ module Impl {
3131
result = this.getVariantList().getAVariant() and
3232
result.getName().getText() = name
3333
}
34+
35+
/*
36+
* Holds if this is a field-less enum, that is, an enum where no constructors
37+
* contain fields.
38+
*/
39+
40+
predicate isFieldless() {
41+
forall(Variant v | v = this.getVariantList().getAVariant() | not v.hasFieldList())
42+
}
3443
}
3544
}

rust/ql/lib/codeql/rust/internal/Type.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class EnumType extends Type, TEnum {
140140

141141
EnumType() { this = TEnum(enum) }
142142

143+
Enum getEnum() { result = enum }
144+
143145
override TypeParameter getPositionalTypeParameter(int i) {
144146
result = TTypeParamTypeParameter(enum.getGenericParamList().getTypeParam(i))
145147
}

0 commit comments

Comments
 (0)