diff options
author | chriseth <chris@ethereum.org> | 2018-08-03 16:18:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-03 16:18:04 +0800 |
commit | 04efbc9e46b3de6572621ba9e5f6683c8a9ded34 (patch) | |
tree | 426d6810bd222bedb7f93545457c1216f7df9b6a | |
parent | 009a55c82d22f08fd207739d7b8aeff215fb7c03 (diff) | |
parent | fb4857abed31a9f63cf3addf53456fdabb269638 (diff) | |
download | dexon-solidity-04efbc9e46b3de6572621ba9e5f6683c8a9ded34.tar dexon-solidity-04efbc9e46b3de6572621ba9e5f6683c8a9ded34.tar.gz dexon-solidity-04efbc9e46b3de6572621ba9e5f6683c8a9ded34.tar.bz2 dexon-solidity-04efbc9e46b3de6572621ba9e5f6683c8a9ded34.tar.lz dexon-solidity-04efbc9e46b3de6572621ba9e5f6683c8a9ded34.tar.xz dexon-solidity-04efbc9e46b3de6572621ba9e5f6683c8a9ded34.tar.zst dexon-solidity-04efbc9e46b3de6572621ba9e5f6683c8a9ded34.zip |
Merge pull request #4657 from ethereum/fix-beyond-STL-end-undefined-behavior
evmasm/Instruction: fixes undefined behavior of advancing iterator beyond the end of a container.
-rw-r--r-- | libevmasm/Instruction.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libevmasm/Instruction.cpp b/libevmasm/Instruction.cpp index f9bbad2c..37c5fdd4 100644 --- a/libevmasm/Instruction.cpp +++ b/libevmasm/Instruction.cpp @@ -21,6 +21,7 @@ #include "./Instruction.h" +#include <algorithm> #include <functional> #include <libdevcore/Common.h> #include <libdevcore/CommonIO.h> @@ -325,13 +326,20 @@ void dev::solidity::eachInstruction( size_t additional = 0; if (isValidInstruction(instr)) additional = instructionInfo(instr).additional; + u256 data; - for (size_t i = 0; i < additional; ++i) + + // fill the data with the additional data bytes from the instruction stream + while (additional > 0 && next(it) < _mem.end()) { data <<= 8; - if (++it < _mem.end()) - data |= *it; + data |= *++it; + --additional; } + + // pad the remaining number of additional octets with zeros + data <<= 8 * additional; + _onInstruction(instr, data); } } |