Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Fix) Removing usage of a free pointer from EternalStorageProxy's fallback function #151

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions contracts/eternal-storage/EternalStorageProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,27 @@ contract EternalStorageProxy is EternalStorage {
* This function will return whatever the implementation call returns
*/
// solhint-disable no-complex-fallback, no-inline-assembly
function() public payable {
function() external payable {
address _impl = _implementation;
require(_impl != address(0));

assembly {
let ptr := mload(0x40)
calldatacopy(ptr, 0, calldatasize)
let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0)
let size := returndatasize
returndatacopy(ptr, 0, size)
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0
calldatacopy(0, 0, calldatasize)

// Call the implementation.
// out and outsize are 0 because we don't know the size yet
let result := delegatecall(gas, _impl, 0, calldatasize, 0, 0)

// Copy the returned data
returndatacopy(0, 0, returndatasize)

switch result
case 0 { revert(ptr, size) }
default { return(ptr, size) }
// delegatecall returns 0 on error
case 0 { revert(0, returndatasize) }
default { return(0, returndatasize) }
}
}
// solhint-enable no-complex-fallback, no-inline-assembly
Expand Down