Skip to content

Commit

Permalink
Merge 29d0f6b into e99180a
Browse files Browse the repository at this point in the history
  • Loading branch information
sohkai committed Oct 25, 2018
2 parents e99180a + 29d0f6b commit 754eb12
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 5 additions & 2 deletions contracts/acl/ACL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,16 @@ contract ACL is IACL, TimeHelpers, AragonApp, ACLHelpers {
* @return boolean indicating whether the ACL allows the role or not
*/
function hasPermission(address _who, address _where, bytes32 _what, bytes memory _how) public view returns (bool) {
// Force cast the bytes array into a uint256[], by overwriting its length
// Note that the uint256[] doesn't need to be initialized as we immediately overwrite it
// with _how and a new length, and _howbecomes invalid from this point forward
uint256[] memory how;
uint256 intsLength = _how.length / 32;
assembly {
how := _how // forced casting
how := _how
mstore(how, intsLength)
}
// _how is invalid from this point fwd

return hasPermission(_who, _where, _what, how);
}

Expand Down
15 changes: 8 additions & 7 deletions contracts/apps/AragonApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ contract AragonApp is AppStorage, Autopetrified, VaultRecoverable, EVMScriptRunn
return false;
}

bytes memory how; // no need to init memory as it is never used
if (_params.length > 0) {
uint256 byteLength = _params.length * 32;
assembly {
how := _params // forced casting
mstore(how, byteLength)
}
// Force cast the uint256[] into a bytes array, by overwriting its length
// Note that the bytes array doesn't need to be initialized as we immediately overwrite it
// with _params and a new length, and _params becomes invalid from this point forward
bytes memory how;
uint256 byteLength = _params.length * 32;
assembly {
how := _params
mstore(how, byteLength)
}
return linkedKernel.hasPermission(_sender, address(this), _role, how);
}
Expand Down
7 changes: 5 additions & 2 deletions contracts/kernel/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,16 @@ contract Kernel is IKernel, KernelStorage, KernelAppIds, KernelNamespaceConstant
}

modifier auth(bytes32 _role, uint256[] memory params) {
// Force cast the uint256[] into a bytes array, by overwriting its length
// Note that the bytes array doesn't need to be initialized as we immediately overwrite it
// with params and a new length, and params becomes invalid from this point forward
bytes memory how;
uint256 byteLength = params.length * 32;
assembly {
how := params // forced casting
how := params
mstore(how, byteLength)
}
// Params is invalid from this point fwd

require(hasPermission(msg.sender, address(this), _role, how), ERROR_AUTH_FAILED);
_;
}
Expand Down

0 comments on commit 754eb12

Please sign in to comment.