diff options
author | Christian Parpart <christian@parpart.family> | 2018-08-02 21:34:14 +0800 |
---|---|---|
committer | Christian Parpart <christian@parpart.family> | 2018-08-03 01:53:46 +0800 |
commit | fb4857abed31a9f63cf3addf53456fdabb269638 (patch) | |
tree | 6844b686d1255f8486de41af74ac659d6879950b /libevmasm/Instruction.cpp | |
parent | 2c61bad3d87dd3585fcd05351f5743251dd23272 (diff) | |
download | dexon-solidity-fb4857abed31a9f63cf3addf53456fdabb269638.tar.gz dexon-solidity-fb4857abed31a9f63cf3addf53456fdabb269638.tar.zst dexon-solidity-fb4857abed31a9f63cf3addf53456fdabb269638.zip |
evmasm/Instruction: fixes undefined behavior of advancing iterator beyond the end of a container.
Usually the STL doesn't check whether or not the developer advances beyond its container's end, but MSVC does (found out by running soltest in debug mode on Win32 / VS2017).
Diffstat (limited to 'libevmasm/Instruction.cpp')
-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); } } |