From 2e7794d8a60dd8d9f12232e356c93f0a95c68a85 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 13 Mar 2019 14:27:25 +0100 Subject: [PATCH] Defensively pad memory for ``type(C).name`` to multiples of 32. --- Changelog.md | 1 + libsolidity/codegen/ExpressionCompiler.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 8cf703976..98f136c0f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ Compiler Features: Bugfixes: + * Code Generator: Defensively pad memory for ``type(Contract).name`` to multiples of 32. Build System: diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 3ed4b702f..986d6b8c7 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1394,7 +1394,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) { TypePointer arg = dynamic_cast(*_memberAccess.expression().annotation().type).typeArgument(); ContractDefinition const& contract = dynamic_cast(*arg).contractDefinition(); - utils().allocateMemory(contract.name().length() + 32); + utils().allocateMemory(((contract.name().length() + 31) / 32) * 32 + 32); // store string length m_context << u256(contract.name().length()) << Instruction::DUP2 << Instruction::MSTORE; // adjust pointer