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

Pointer to uninitialized External Function struct should not be null #944

Open
LucasSte opened this issue Aug 1, 2022 · 3 comments
Open
Labels
bug Something isn't working

Comments

@LucasSte
Copy link
Contributor

LucasSte commented Aug 1, 2022

This contract causes an access violation in Solana's mock VM, because fun is a null pointer.

contract C {

    function test(uint256 newAddress, bytes4 newSelector) public view returns (bytes4, address) {
        function() external fun;
        address myAddr = address(newAddress);
        assembly {
            fun.selector := myAddr
            fun.address  := newAddress
        }

        return (fun.selector, fun.address);
    }
}
@LucasSte LucasSte added the bug Something isn't working label Aug 1, 2022
@xermicus
Copy link
Contributor

This won't even compile with solc:

Error: Explicit type conversion not allowed from "uint256" to "address".
 --> bug.sol:7:26:
  |
7 |         address myAddr = address(newAddress);
  |                          ^^^^^^^^^^^^^^^^^^^

@seanyoung
Copy link
Contributor

This won't even compile with solc:

Error: Explicit type conversion not allowed from "uint256" to "address".
 --> bug.sol:7:26:
  |
7 |         address myAddr = address(newAddress);
  |                          ^^^^^^^^^^^^^^^^^^^

That's because an address is 20 bytes on ethereum. I think this will work:

contract C {

    function test(uint160 newAddress, bytes4 newSelector) public view returns (bytes4, address) {
        function() external fun;
        address myAddr = address(newAddress);
        assembly {
            fun.selector := myAddr
            fun.address  := newAddress
        }

        return (fun.selector, fun.address);
    }
}

@xermicus
Copy link
Contributor

Of course, maybe next time I should read the contract first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants