Skip to content

Commit badfc23

Browse files
authored
Merge pull request github#1718 from aschackmull/java/barrierguard
Java/C++/C#: Add support for BarrierGuards.
2 parents e93598e + c99d0e7 commit badfc23

File tree

25 files changed

+254
-0
lines changed

25 files changed

+254
-0
lines changed

change-notes/1.22/analysis-java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|----------------------------|------------------------|------------------------------------------------------------------|
77
| Equals method does not inspect argument type (`java/unchecked-cast-in-equals`) | Fewer false positive and more true positive results | Precision has been improved by doing a bit of inter-procedural analysis and relying less on ad-hoc method names. |
88
| Uncontrolled data in arithmetic expression (`java/uncontrolled-arithmetic`) | Fewer false positive results | Precision has been improved in several ways, in particular, by better detection of guards along the data-flow path. |
9+
| Uncontrolled data used in path expression (`java/path-injection`) | Fewer false positive results | The query no longer reports results guarded by `!var.contains("..")`. |
910
| User-controlled data in arithmetic expression (`java/tainted-arithmetic`) | Fewer false positive results | Precision has been improved in several ways, in particular, by better detection of guards along the data-flow path. |
1011

1112
## Changes to QL libraries

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowUtil.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,22 @@ VariableAccess getAnAccessToAssignedVariable(Expr assign) {
331331
result = var.getAnAccess()
332332
)
333333
}
334+
335+
/**
336+
* A guard that validates some expression.
337+
*
338+
* To use this in a configuration, extend the class and provide a
339+
* characteristic predicate precisely specifying the guard, and override
340+
* `checks` to specify what is being validated and in which branch.
341+
*
342+
* It is important that all extending classes in scope are disjoint.
343+
*/
344+
class BarrierGuard extends Expr {
345+
/** NOT YET SUPPORTED. Holds if this guard validates `e` upon evaluating to `branch`. */
346+
abstract deprecated predicate checks(Expr e, boolean branch);
347+
348+
/** Gets a node guarded by this guard. */
349+
final Node getAGuardedNode() {
350+
none() // stub
351+
}
352+
}

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl2.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl3.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl4.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ abstract class Configuration extends string {
7575
/** Holds if data flow out of `node` is prohibited. */
7676
predicate isBarrierOut(Node node) { none() }
7777

78+
/** Holds if data flow through nodes guarded by `guard` is prohibited. */
79+
predicate isBarrierGuard(BarrierGuard guard) { none() }
80+
7881
/**
7982
* Holds if the additional flow step from `node1` to `node2` must be taken
8083
* into account in the analysis.
@@ -136,6 +139,11 @@ private predicate fullBarrier(Node node, Configuration config) {
136139
or
137140
config.isBarrierOut(node) and
138141
not config.isSink(node)
142+
or
143+
exists(BarrierGuard g |
144+
config.isBarrierGuard(g) and
145+
node = g.getAGuardedNode()
146+
)
139147
}
140148

141149
private class AdditionalFlowStepSource extends Node {

0 commit comments

Comments
 (0)