Skip to content

Commit

Permalink
Cleanup and another overflow check.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Oct 13, 2017
1 parent 146d233 commit 6072d29
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions libsolidity/codegen/ABIFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory)
if (_fromMemory)
functionName += "_fromMemory";

return createFunction(functionName, [&]() {
solAssert(!_types.empty(), "");
solAssert(!_types.empty(), "");

return createFunction(functionName, [&]() {
TypePointers decodingTypes;
for (auto const& t: _types)
decodingTypes.emplace_back(t->decodingType());
Expand Down Expand Up @@ -1078,7 +1078,14 @@ string ABIFunctions::abiDecodingFunction(Type const& _type, bool _fromMemory, bo
return abiDecodingFunctionStruct(*structType, _fromMemory);
else if (auto const* functionType = dynamic_cast<FunctionType const*>(decodingType.get()))
return abiDecodingFunctionFunctionType(*functionType, _fromMemory, _forUseOnStack);
else
return abiDecodingFunctionValueType(_type, _fromMemory);
}

string ABIFunctions::abiDecodingFunctionValueType(const Type& _type, bool _fromMemory)
{
TypePointer decodingType = _type.decodingType();
solAssert(decodingType, "");
solAssert(decodingType->sizeOnStack() == 1, "");
solAssert(decodingType->isValueType(), "");
solAssert(decodingType->calldataEncodedSize() == 32, "");
Expand All @@ -1101,6 +1108,7 @@ string ABIFunctions::abiDecodingFunction(Type const& _type, bool _fromMemory, bo
templ("cleanup", cleanupFunction(_type, true));
return templ.render();
});

}

string ABIFunctions::abiDecodingFunctionArray(ArrayType const& _type, bool _fromMemory)
Expand Down Expand Up @@ -1611,7 +1619,8 @@ string ABIFunctions::allocationFunction()
function <functionName>(size) -> memPtr {
memPtr := mload(<freeMemoryPointer>)
let newFreePtr := add(memPtr, size)
switch lt(newFreePtr, memPtr) case 1 { revert(0, 0) }
// protect against overflow
switch or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) case 1 { revert(0, 0) }
mstore(<freeMemoryPointer>, newFreePtr)
}
)")
Expand Down
4 changes: 3 additions & 1 deletion libsolidity/codegen/ABIFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ABIFunctions
bool _fromStack
);

/// @returns the name of the ABI decodinf function for the given type
/// @returns the name of the ABI decoding function for the given type
/// and queues the generation of the function to the requested functions.
/// The caller has to ensure that no out of bounds access (at least to the static
/// part) can happen inside this function.
Expand All @@ -172,6 +172,8 @@ class ABIFunctions
bool _forUseOnStack
);

/// Part of @a abiDecodingFunction for value types.
std::string abiDecodingFunctionValueType(Type const& _type, bool _fromMemory);
/// Part of @a abiDecodingFunction for "regular" array types.
std::string abiDecodingFunctionArray(ArrayType const& _type, bool _fromMemory);
/// Part of @a abiDecodingFunction for calldata array types.
Expand Down
1 change: 0 additions & 1 deletion libsolidity/codegen/CompilerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ void CompilerContext::appendInlineAssembly(

ErrorList errors;
ErrorReporter errorReporter(errors);
// cout << _assembly << endl;
auto scanner = make_shared<Scanner>(CharStream(_assembly), "--CODEGEN--");
auto parserResult = assembly::Parser(errorReporter).parse(scanner);
#ifdef SOL_OUTPUT_ASM
Expand Down
1 change: 0 additions & 1 deletion libsolidity/codegen/ContractCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,6 @@ void ContractCompiler::appendMissingFunctions()
}
m_context.appendMissingLowLevelFunctions();
string abiFunctions = m_context.abiFunctions().requestedFunctions();
// cout << abiFunctions << endl;
if (!abiFunctions.empty())
m_context.appendInlineAssembly("{" + move(abiFunctions) + "}", {}, true);
}
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/ABIDecoderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace test

BOOST_FIXTURE_TEST_SUITE(ABIDecoderTest, SolidityExecutionFramework)

BOOST_AUTO_TEST_CASE(BOTH_ENCODERS_macro)
BOOST_AUTO_TEST_CASE(both_encoders_macro)
{
// This tests that the "both decoders macro" at least runs twice and
// modifies the source.
Expand Down

0 comments on commit 6072d29

Please sign in to comment.