Merge branch 'dev-fix-data-dependency' into dev

pull/217/head
Josselin 6 years ago
commit 6a4ad1893e
  1. 13
      examples/scripts/data_dependency.sol
  2. 4
      slither/analyses/data_dependency/data_dependency.py
  3. 38
      slither/core/declarations/function.py
  4. 1
      slither/core/expressions/__init__.py

@ -102,3 +102,16 @@ contract PropagateThroughArguments {
var_not_tainted = y;
}
}
contract PropagateThroughReturnValue {
uint var_dependant;
uint var_state;
function foo() public {
var_dependant = bar();
}
function bar() internal returns (uint) {
return (var_state);
}
}

@ -4,7 +4,7 @@
from slither.core.declarations import (Contract, Enum, Function,
SolidityFunction, SolidityVariable,
SolidityVariableComposed, Structure)
from slither.slithir.operations import Index, OperationWithLValue
from slither.slithir.operations import Index, OperationWithLValue, InternalCall
from slither.slithir.variables import (Constant, LocalIRVariable,
ReferenceVariable, ReferenceVariableSSA,
StateIRVariable, TemporaryVariable,
@ -232,6 +232,8 @@ def add_dependency(lvalue, function, ir, is_protected):
function.context[KEY_SSA_UNPROTECTED][lvalue] = set()
if isinstance(ir, Index):
read = [ir.variable_left]
elif isinstance(ir, InternalCall):
read = ir.function.return_values_ssa
else:
read = ir.read
[function.context[KEY_SSA][lvalue].add(v) for v in read if not isinstance(v, Constant)]

@ -9,10 +9,8 @@ from slither.core.children.child_contract import ChildContract
from slither.core.declarations.solidity_variables import (SolidityFunction,
SolidityVariable,
SolidityVariableComposed)
from slither.core.expressions.identifier import Identifier
from slither.core.expressions.index_access import IndexAccess
from slither.core.expressions.member_access import MemberAccess
from slither.core.expressions.unary_operation import UnaryOperation
from slither.core.expressions import (Identifier, IndexAccess, MemberAccess,
UnaryOperation)
from slither.core.source_mapping.source_mapping import SourceMapping
from slither.core.variables.state_variable import StateVariable
@ -43,6 +41,8 @@ class Function(ChildContract, SourceMapping):
self._parameters_ssa = []
self._returns = []
self._returns_ssa = []
self._return_values = None
self._return_values_ssa = None
self._vars_read = []
self._vars_written = []
self._state_vars_read = []
@ -468,6 +468,36 @@ class Function(ChildContract, SourceMapping):
self._expressions = expressions
return self._expressions
@property
def return_values(self):
"""
list(Return Values): List of the return values
"""
from slither.core.cfg.node import NodeType
from slither.slithir.operations import Return
if self._return_values is None:
return_values = list()
returns = [n for n in self.nodes if n.type == NodeType.RETURN]
[return_values.extend(ir.values) for node in returns for ir in node.irs if isinstance(ir, Return)]
self._return_values = list(set(return_values))
return self._return_values
@property
def return_values_ssa(self):
"""
list(Return Values in SSA form): List of the return values in ssa form
"""
from slither.core.cfg.node import NodeType
from slither.slithir.operations import Return
if self._return_values_ssa is None:
return_values_ssa = list()
returns = [n for n in self.nodes if n.type == NodeType.RETURN]
[return_values_ssa.extend(ir.values) for node in returns for ir in node.irs_ssa if isinstance(ir, Return)]
self._return_values_ssa = list(set(return_values_ssa))
return self._return_values_ssa
# endregion
###################################################################################
###################################################################################

@ -6,6 +6,7 @@ from .elementary_type_name_expression import ElementaryTypeNameExpression
from .identifier import Identifier
from .index_access import IndexAccess
from .literal import Literal
from .member_access import MemberAccess
from .new_array import NewArray
from .new_contract import NewContract
from .new_elementary_type import NewElementaryType

Loading…
Cancel
Save