@@ -33,8 +33,9 @@ predicate allocSink(HeuristicAllocationExpr alloc, DataFlow::Node sink) {
3333 )
3434}
3535
36- predicate readsVariable ( LoadInstruction load , Variable var ) {
37- load .getSourceAddress ( ) .( VariableAddressInstruction ) .getAstVariable ( ) = var
36+ predicate readsVariable ( LoadInstruction load , Variable var , IRBlock bb ) {
37+ load .getSourceAddress ( ) .( VariableAddressInstruction ) .getAstVariable ( ) = var and
38+ bb = load .getBlock ( )
3839}
3940
4041predicate hasUpperBoundsCheck ( Variable var ) {
@@ -46,10 +47,18 @@ predicate hasUpperBoundsCheck(Variable var) {
4647 )
4748}
4849
49- predicate nodeIsBarrierEqualityCandidate ( DataFlow:: Node node , Operand access , Variable checkedVar ) {
50- exists ( Instruction instr | instr = node .asOperand ( ) .getDef ( ) |
51- readsVariable ( instr , checkedVar ) and
52- any ( IRGuardCondition guard ) .ensuresEq ( access , _, _, instr .getBlock ( ) , true )
50+ predicate variableEqualityCheckedInBlock ( Variable checkedVar , IRBlock bb ) {
51+ exists ( Operand access |
52+ readsVariable ( access .getDef ( ) , checkedVar , _) and
53+ any ( IRGuardCondition guard ) .ensuresEq ( access , _, _, bb , true )
54+ )
55+ }
56+
57+ predicate nodeIsBarrierEquality ( DataFlow:: Node node ) {
58+ exists ( Variable checkedVar , Instruction instr , IRBlock bb |
59+ instr = node .asOperand ( ) .getDef ( ) and
60+ readsVariable ( instr , checkedVar , bb ) and
61+ variableEqualityCheckedInBlock ( checkedVar , bb )
5362 )
5463}
5564
@@ -72,14 +81,11 @@ module TaintedAllocationSizeConfig implements DataFlow::ConfigSig {
7281 )
7382 or
7483 exists ( Variable checkedVar , Instruction instr | instr = node .asOperand ( ) .getDef ( ) |
75- readsVariable ( instr , checkedVar ) and
84+ readsVariable ( instr , checkedVar , _ ) and
7685 hasUpperBoundsCheck ( checkedVar )
7786 )
7887 or
79- exists ( Variable checkedVar , Operand access |
80- readsVariable ( access .getDef ( ) , checkedVar ) and
81- nodeIsBarrierEqualityCandidate ( node , access , checkedVar )
82- )
88+ nodeIsBarrierEquality ( node )
8389 or
8490 // block flow to inside of identified allocation functions (this flow leads
8591 // to duplicate results)
0 commit comments