Fix incorrect state variable read in case of ReferenceVariable

pull/162/head
Josselin 6 years ago
parent bcb3e5b5f0
commit 1cdc34ec77
  1. 10
      slither/core/cfg/node.py

@ -525,7 +525,12 @@ class Node(SourceMapping, ChildFunction):
if var and self._is_valid_slithir_var(var): if var and self._is_valid_slithir_var(var):
self._slithir_vars.add(var) self._slithir_vars.add(var)
if not isinstance(ir, (Phi, Index, Member)):
self._vars_read += [v for v in ir.read if self._is_non_slithir_var(v)] self._vars_read += [v for v in ir.read if self._is_non_slithir_var(v)]
for var in ir.read:
if isinstance(var, (ReferenceVariable)):
self._vars_read.append(var.points_to_origin)
if isinstance(ir, OperationWithLValue): if isinstance(ir, OperationWithLValue):
if isinstance(ir, (Index, Member, Length, Balance)): if isinstance(ir, (Index, Member, Length, Balance)):
continue # Don't consider Member and Index operations -> ReferenceVariable continue # Don't consider Member and Index operations -> ReferenceVariable
@ -582,9 +587,13 @@ class Node(SourceMapping, ChildFunction):
for ir in self.irs_ssa: for ir in self.irs_ssa:
if isinstance(ir, (PhiCallback)): if isinstance(ir, (PhiCallback)):
continue continue
if not isinstance(ir, (Phi, Index, Member)):
self._ssa_vars_read += [v for v in ir.read if isinstance(v, self._ssa_vars_read += [v for v in ir.read if isinstance(v,
(StateIRVariable, (StateIRVariable,
LocalIRVariable))] LocalIRVariable))]
for var in ir.read:
if isinstance(var, (ReferenceVariable)):
self._vars_read.append(var.points_to_origin)
if isinstance(ir, OperationWithLValue): if isinstance(ir, OperationWithLValue):
if isinstance(ir, (Index, Member, Length, Balance)): if isinstance(ir, (Index, Member, Length, Balance)):
continue # Don't consider Member and Index operations -> ReferenceVariable continue # Don't consider Member and Index operations -> ReferenceVariable
@ -596,7 +605,6 @@ class Node(SourceMapping, ChildFunction):
if isinstance(ir, (PhiCallback)): if isinstance(ir, (PhiCallback)):
continue continue
self._ssa_vars_written.append(var) self._ssa_vars_written.append(var)
self._ssa_vars_read = list(set(self._ssa_vars_read)) self._ssa_vars_read = list(set(self._ssa_vars_read))
self._ssa_state_vars_read = [v for v in self._ssa_vars_read if isinstance(v, StateVariable)] self._ssa_state_vars_read = [v for v in self._ssa_vars_read if isinstance(v, StateVariable)]
self._ssa_local_vars_read = [v for v in self._ssa_vars_read if isinstance(v, LocalVariable)] self._ssa_local_vars_read = [v for v in self._ssa_vars_read if isinstance(v, LocalVariable)]

Loading…
Cancel
Save