Python: Add StringConstCompare BarrierGuard

This commit is contained in:
Rasmus Wriedt Larsen
2020-11-20 10:40:04 +01:00
parent a82936c904
commit 1a52f17da3
5 changed files with 28 additions and 2 deletions

View File

@@ -355,6 +355,26 @@ class BarrierGuard extends GuardNode {
}
}
/** Provides commonly used BarrierGuards */
module BarrierGuard {
/** A validation of unknown node by comparing with a constant string value. */
class StringConstCompare extends BarrierGuard, CompareNode {
ControlFlowNode checked_node;
StringConstCompare() {
exists(StrConst str_const |
this.operands(str_const.getAFlowNode(), any(Eq eq), checked_node)
or
this.operands(checked_node, any(Eq eq), str_const.getAFlowNode())
)
}
override predicate checks(ControlFlowNode node, boolean branch) {
node = checked_node and branch = true
}
}
}
/**
* Algebraic datatype for tracking data content associated with values.
* Content can be collection elements or object attributes.