Improve read var info for Index/Member operatioln

Fix minor bug in reentrancy read_before_write
pull/162/head
Josselin 6 years ago
parent 7d04cc049d
commit 5dc98b20b5
  1. 20
      slither/core/cfg/node.py
  2. 2
      slither/detectors/reentrancy/reentrancy_read_before_write.py

@ -530,6 +530,13 @@ class Node(SourceMapping, ChildFunction):
for var in ir.read:
if isinstance(var, (ReferenceVariable)):
self._vars_read.append(var.points_to_origin)
elif isinstance(ir, (Member, Index)):
if self._is_non_slithir_var(ir.variable_right):
self._vars_read.append(ir.variable_right)
if isinstance(ir.variable_right, (ReferenceVariable)):
origin = ir.variable_right.points_to_origin
if self._is_non_slithir_var:
self._vars_read.append(origin)
if isinstance(ir, OperationWithLValue):
if isinstance(ir, (Index, Member, Length, Balance)):
@ -593,7 +600,18 @@ class Node(SourceMapping, ChildFunction):
LocalIRVariable))]
for var in ir.read:
if isinstance(var, (ReferenceVariable)):
self._vars_read.append(var.points_to_origin)
origin = var.points_to_origin
if isinstance(origin, (StateIRVariable, LocalIRVariable)):
self._ssa_vars_read.append(origin)
elif isinstance(ir, (Member, Index)):
if isinstance(ir.variable_right, (StateIRVariable, LocalIRVariable)):
self._ssa_vars_read.append(ir.variable_right)
if isinstance(ir.variable_right, (ReferenceVariable)):
origin = ir.variable_right.points_to_origin
if isinstance(origin, (StateIRVariable, LocalIRVariable)):
self._ssa_vars_read.append(origin)
if isinstance(ir, OperationWithLValue):
if isinstance(ir, (Index, Member, Length, Balance)):
continue # Don't consider Member and Index operations -> ReferenceVariable

@ -42,7 +42,7 @@ class ReentrancyReadBeforeWritten(Reentrancy):
finding_key = (node.function,
tuple(set(node.context[self.KEY]['calls'])))
finding_vars = read_then_written
if finding_key not in self.result:
if finding_key not in result:
result[finding_key] = []
result[finding_key] = list(set(result[finding_key] + finding_vars))
return result

Loading…
Cancel
Save