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.
This commit is contained in:
chriseth 2018-08-03 10:18:04 +02:00 committed by GitHub
commit 04efbc9e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}