Browse Source

Deprecate Memory::require(size) function. Risk of unsigned integer overflow.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
273b0f634f
  1. 9
      libevmjit/Compiler.cpp
  2. 2
      libevmjit/Memory.cpp
  3. 7
      libevmjit/Memory.h

9
libevmjit/Compiler.cpp

@ -785,12 +785,9 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
gasMeter.commitCostBlock(gas);
// Require memory for the max of in and out buffers
auto inSizeReq = m_builder.CreateAdd(inOff, inSize, "inSizeReq");
auto outSizeReq = m_builder.CreateAdd(outOff, outSize, "outSizeReq");
auto cmp = m_builder.CreateICmpUGT(inSizeReq, outSizeReq);
auto sizeReq = m_builder.CreateSelect(cmp, inSizeReq, outSizeReq, "sizeReq");
memory.require(sizeReq);
// Require memory for in and out buffers
memory.require(outOff, outSize); // Out buffer first as we guess it will be after the in one
memory.require(inOff, inSize);
auto receiveAddress = codeAddress;
if (inst == Instruction::CALLCODE)

2
libevmjit/Memory.cpp

@ -171,7 +171,7 @@ void Memory::require(llvm::Value* _size)
void Memory::require(llvm::Value* _offset, llvm::Value* _size)
{
auto sizeRequired = m_builder.CreateAdd(_offset, _size, "sizeRequired");
auto sizeRequired = m_builder.CreateNUWAdd(_offset, _size, "sizeRequired");
require(sizeRequired);
}

7
libevmjit/Memory.h

@ -24,9 +24,6 @@ public:
void copyBytes(llvm::Value* _srcPtr, llvm::Value* _srcSize, llvm::Value* _srcIndex,
llvm::Value* _destMemIdx, llvm::Value* _byteCount);
/// Requires this amount of memory. And counts gas fee for that memory.
void require(llvm::Value* _size);
/// Requires the amount of memory to for data defined by offset and size. And counts gas fee for that memory.
void require(llvm::Value* _offset, llvm::Value* _size);
@ -36,7 +33,9 @@ private:
llvm::Function* createFunc(bool _isStore, llvm::Type* _type, GasMeter& _gasMeter);
llvm::Function* createRequireFunc(GasMeter& _gasMeter, RuntimeManager& _runtimeManager);
private:
/// Requires this amount of memory. And counts gas fee for that memory.
void require(llvm::Value* _size);
llvm::GlobalVariable* m_data;
llvm::GlobalVariable* m_size;

Loading…
Cancel
Save