git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit a51f04b0499d6c309d071a010595bc54b0086074

add bounds checking

wanderer committed on 1/6/2017, 3:14:05 AM
Parent: 5f3238f523d36fc8df666fb57dcef2f8ecdd2a37

Files changed

EVMimports.jschanged
tests/interfaceRunner.jschanged
EVMimports.jsView
@@ -187,9 +187,9 @@
187187 */
188188 callDataCopy (offset, dataOffset, length) {
189189 this.takeGas(3 + Math.ceil(length / 32) * 3)
190190
191- if (length) {
191+ if (length > 0 && offset >= 0 && dataOffset >= 0) {
192192 const callData = this.kernel.environment.callData.slice(dataOffset, dataOffset + length)
193193 this.setMemory(offset, length, callData)
194194 }
195195 }
@@ -201,8 +201,9 @@
201201 * @param {integer} dataOffset the offset in the input data
202202 */
203203 callDataCopy256 (offset, dataOffset) {
204204 this.takeGas(3)
205+
205206 const callData = this.kernel.environment.callData.slice(dataOffset, dataOffset + 32)
206207 this.setMemory(offset, U256_SIZE_BYTES, callData)
207208 }
208209
@@ -336,9 +337,9 @@
336337 */
337338 getBlockCoinbase (offset) {
338339 this.takeGas(2)
339340
340- this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.coinbase.toMemory())
341+ this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.block.header.coinbase)
341342 }
342343
343344 /**
344345 * Get the block’s timestamp.
@@ -603,11 +604,9 @@
603604 * @param {integer} offset the offset of the output data.
604605 * @param {integer} length the length of the output data.
605606 */
606607 return (offset, length) {
607- if (length) {
608- this.kernel.environment.returnValue = this.getMemory(offset, length).slice(0)
609- }
608+ this.kernel.environment.returnValue = this.getMemory(offset, length).slice(0)
610609 }
611610
612611 /**
613612 * Halt execution and register account for later deletion giving the remaining
@@ -620,14 +619,20 @@
620619 this.kernel.environment.gasRefund += 24000
621620 }
622621
623622 getMemory (offset, length) {
624- return new Uint8Array(this.kernel.memory, offset, length)
623+ if (offset >= 0 && length > 0) {
624+ return new Uint8Array(this.kernel.memory, offset, length)
625+ } else {
626+ return new Uint8Array([])
627+ }
625628 }
626629
627630 setMemory (offset, length, value) {
628- const memory = new Uint8Array(this.kernel.memory, offset, length)
629- memory.set(value)
631+ if (offset >= 0 && length > 0) {
632+ const memory = new Uint8Array(this.kernel.memory, offset, length)
633+ memory.set(value)
634+ }
630635 }
631636
632637 /*
633638 * Takes gas from the tank. Only needs to check if there's gas left to be taken,
tests/interfaceRunner.jsView
@@ -3,8 +3,9 @@
33 const path = require('path')
44 const Vertex = require('merkle-trie')
55 const Address = require('../deps/address')
66 const U256 = require('../deps/u256')
7+const Block = require('../deps/block.js')
78
89 const Kernel = require('../index.js')
910 const Environment = require('../testEnvironment.js')
1011
@@ -22,11 +23,12 @@
2223 const rootVertex = new Vertex()
2324 const code = fs.readFileSync(`${dir}/${testName}.wasm`)
2425 const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
2526
27+ envData.block = new Block()
2628 envData.caller = new Address(envData.caller)
2729 envData.address = new Address(envData.address)
28- envData.coinbase = new Address(envData.coinbase)
30+ envData.block.header.coinbase = new Address(envData.coinbase)
2931 envData.origin = new Address(envData.origin)
3032 envData.callData = new Buffer(envData.callData.slice(2), 'hex')
3133 envData.callValue = new U256(envData.callValue)
3234

Built with git-ssb-web