Skip to content

Commit 6050a0e

Browse files
committed
Rust: Split boolean from number barriers
1 parent 1c8cc39 commit 6050a0e

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

rust/ql/lib/codeql/rust/security/Barriers.qll

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Classes to represent barriers commonly used in dataflow and taint tracking
2+
* Classes to represent barriers commonly used in data flow and taint tracking
33
* configurations.
44
*/
55

@@ -11,35 +11,26 @@ private import codeql.rust.controlflow.ControlFlowGraph as Cfg
1111
private import codeql.rust.controlflow.CfgNodes as CfgNodes
1212
private import codeql.rust.frameworks.stdlib.Builtins as Builtins
1313

14-
/**
15-
* A node whose type is a numeric or boolean type, which may be an appropriate
16-
* taint flow barrier for some queries.
17-
*/
14+
/** A node whose type is a numeric. */
1815
class NumericTypeBarrier extends DataFlow::Node {
1916
NumericTypeBarrier() {
20-
exists(StructType t, Struct s |
21-
t = TypeInference::inferType(this.asExpr()) and
22-
s = t.getStruct()
23-
|
24-
s instanceof Builtins::NumericType or
25-
s instanceof Builtins::Bool
26-
)
17+
TypeInference::inferType(this.asExpr()).(StructType).getStruct() instanceof
18+
Builtins::NumericType
2719
}
2820
}
2921

30-
/**
31-
* A node whose type is an integral (integer) or boolean type, which may be an
32-
* appropriate taint flow barrier for some queries.
33-
*/
34-
class IntegralOrBooleanTypeBarrier extends DataFlow::Node {
35-
IntegralOrBooleanTypeBarrier() {
36-
exists(StructType t, Struct s |
37-
t = TypeInference::inferType(this.asExpr()) and
38-
s = t.getStruct()
39-
|
40-
s instanceof Builtins::IntegralType or
41-
s instanceof Builtins::Bool
42-
)
22+
/** A node whose type is `bool`. */
23+
class BooleanTypeBarrier extends DataFlow::Node {
24+
BooleanTypeBarrier() {
25+
TypeInference::inferType(this.asExpr()).(StructType).getStruct() instanceof Builtins::Bool
26+
}
27+
}
28+
29+
/** A node whose type is an integral (integer). */
30+
class IntegralTypeBarrier extends DataFlow::Node {
31+
IntegralTypeBarrier() {
32+
TypeInference::inferType(this.asExpr()).(StructType).getStruct() instanceof
33+
Builtins::IntegralType
4334
}
4435
}
4536

rust/ql/lib/codeql/rust/security/LogInjectionExtensions.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ module LogInjection {
4949
* numeric or boolean type, which is unlikely to expose any vulnerability.
5050
*/
5151
private class NumericTypeBarrier extends Barrier instanceof Barriers::NumericTypeBarrier { }
52+
53+
private class BooleanTypeBarrier extends Barrier instanceof Barriers::BooleanTypeBarrier { }
5254
}

rust/ql/lib/codeql/rust/security/SqlInjectionExtensions.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ module SqlInjection {
6464
* boolean type, which is unlikely to expose any vulnerability.
6565
*/
6666
private class NumericTypeBarrier extends Barrier instanceof Barriers::NumericTypeBarrier { }
67+
68+
private class BooleanTypeBarrier extends Barrier instanceof Barriers::BooleanTypeBarrier { }
6769
}

rust/ql/lib/codeql/rust/security/regex/RegexInjectionExtensions.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ module RegexInjection {
9494
* We don't include floating point types in this barrier, as `.` is a special character
9595
* in regular expressions.
9696
*/
97-
private class IntegralOrBooleanTypeBarrier extends Barrier instanceof Barriers::IntegralOrBooleanTypeBarrier
98-
{ }
97+
private class IntegralTypeBarrier extends Barrier instanceof Barriers::IntegralTypeBarrier { }
98+
99+
private class BooleanTypeBarrier extends Barrier instanceof Barriers::BooleanTypeBarrier { }
99100
}

0 commit comments

Comments
 (0)