mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
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:
commit
04efbc9e46
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "./Instruction.h"
|
#include "./Instruction.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
#include <libdevcore/CommonIO.h>
|
#include <libdevcore/CommonIO.h>
|
||||||
@ -325,13 +326,20 @@ void dev::solidity::eachInstruction(
|
|||||||
size_t additional = 0;
|
size_t additional = 0;
|
||||||
if (isValidInstruction(instr))
|
if (isValidInstruction(instr))
|
||||||
additional = instructionInfo(instr).additional;
|
additional = instructionInfo(instr).additional;
|
||||||
|
|
||||||
u256 data;
|
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;
|
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);
|
_onInstruction(instr, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user