Merge pull request #6596 from ethereum/backportUnititializedFunctionFix

Backport: Fix use of uninitialized functions stored in storage.
This commit is contained in:
chriseth 2019-04-25 16:59:55 +02:00 committed by GitHub
commit 9861145ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 0 deletions

View File

@ -1,5 +1,8 @@
### 0.4.26 (unreleased)
Important Bugfixes:
* Code Generator: Fix initialization routine of uninitialized internal function pointers in constructor context.
Bugfixes:
* General: Split rule list such that JavaScript environments with small stacks can use the compiler.

View File

@ -1060,6 +1060,14 @@ void CompilerUtils::pushZeroValue(Type const& _type)
m_context << m_context.lowLevelFunctionTag("$invalidFunction", 0, 0, [](CompilerContext& _context) {
_context.appendInvalid();
});
if (CompilerContext* runCon = m_context.runtimeContext())
{
leftShiftNumberOnStack(32);
m_context << runCon->lowLevelFunctionTag("$invalidFunction", 0, 0, [](CompilerContext& _context) {
_context.appendInvalid();
}).toSubAssemblyTag(m_context.runtimeSub());
m_context << Instruction::OR;
}
return;
}
}

View File

@ -0,0 +1,23 @@
contract C {
function() internal storedFn;
bool flag;
constructor() public {
if (!flag) {
flag = true;
function() internal invalid;
storedFn = invalid;
invalid();
}
}
function f() public pure {}
}
contract Test {
function f() public {
new C();
}
}
// ----
// f() -> FAILURE

View File

@ -0,0 +1,23 @@
contract C {
function() internal storedFn;
bool flag;
constructor() public {
if (!flag) {
flag = true;
function() internal invalid;
storedFn = invalid;
storedFn();
}
}
function f() public pure {}
}
contract Test {
function f() public {
new C();
}
}
// ----
// f() -> FAILURE

View File

@ -0,0 +1,19 @@
contract InvalidTest {
function() internal storedFn;
bool flag;
constructor() public {
function() internal invalid;
storedFn = invalid;
}
function f() public returns (uint) {
if (flag) return 2;
flag = true;
storedFn();
}
}
// ----
// f() -> FAILURE
// f() -> FAILURE