|
3 | 3 | private import python |
4 | 4 | private import semmle.python.dataflow.new.DataFlow |
5 | 5 |
|
6 | | -private predicate stringConstCompare(DataFlow::GuardNode g, ControlFlowNode node, boolean branch) { |
| 6 | +private predicate constCompare(DataFlow::GuardNode g, ControlFlowNode node, boolean branch) { |
7 | 7 | exists(CompareNode cn | cn = g | |
8 | | - exists(StringLiteral str_const, Cmpop op | |
| 8 | + exists(ImmutableLiteral const, Cmpop op | |
9 | 9 | op = any(Eq eq) and branch = true |
10 | 10 | or |
11 | 11 | op = any(NotEq ne) and branch = false |
12 | 12 | | |
13 | | - cn.operands(str_const.getAFlowNode(), op, node) |
| 13 | + cn.operands(const.getAFlowNode(), op, node) |
14 | 14 | or |
15 | | - cn.operands(node, op, str_const.getAFlowNode()) |
| 15 | + cn.operands(node, op, const.getAFlowNode()) |
16 | 16 | ) |
17 | 17 | or |
18 | | - exists(IterableNode str_const_iterable, Cmpop op | |
| 18 | + exists(NameConstant const, Cmpop op | |
| 19 | + op = any(Is is_) and branch = true |
| 20 | + or |
| 21 | + op = any(IsNot isn) and branch = false |
| 22 | + | |
| 23 | + cn.operands(const.getAFlowNode(), op, node) |
| 24 | + or |
| 25 | + cn.operands(node, op, const.getAFlowNode()) |
| 26 | + ) |
| 27 | + or |
| 28 | + exists(IterableNode const_iterable, Cmpop op | |
19 | 29 | op = any(In in_) and branch = true |
20 | 30 | or |
21 | 31 | op = any(NotIn ni) and branch = false |
22 | 32 | | |
23 | | - forall(ControlFlowNode elem | elem = str_const_iterable.getAnElement() | |
24 | | - elem.getNode() instanceof StringLiteral |
| 33 | + forall(ControlFlowNode elem | elem = const_iterable.getAnElement() | |
| 34 | + elem.getNode() instanceof ImmutableLiteral |
25 | 35 | ) and |
26 | | - cn.operands(node, op, str_const_iterable) |
| 36 | + cn.operands(node, op, const_iterable) |
27 | 37 | ) |
28 | 38 | ) |
29 | 39 | } |
30 | 40 |
|
31 | | -/** A validation of unknown node by comparing with a constant string value. */ |
32 | | -class StringConstCompareBarrier extends DataFlow::Node { |
33 | | - StringConstCompareBarrier() { |
34 | | - this = DataFlow::BarrierGuard<stringConstCompare/3>::getABarrierNode() |
35 | | - } |
| 41 | +/** A validation of unknown node by comparing with a constant value. */ |
| 42 | +class ConstCompareBarrier extends DataFlow::Node { |
| 43 | + ConstCompareBarrier() { this = DataFlow::BarrierGuard<constCompare/3>::getABarrierNode() } |
36 | 44 | } |
| 45 | + |
| 46 | +/** DEPRECATED: Use ConstCompareBarrier instead. */ |
| 47 | +deprecated class StringConstCompareBarrier = ConstCompareBarrier; |
0 commit comments