Merge pull request #395 from ethereum/rust-buffers

rust: enforce EVMC rules on message and result buffers
This commit is contained in:
Paweł Bylica 2019-08-09 14:05:27 +02:00 committed by GitHub
commit 7aa609a6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -351,7 +351,12 @@ impl From<ffi::evmc_result> for ExecutionResult {
let ret = ExecutionResult {
status_code: result.status_code,
gas_left: result.gas_left,
output: if !result.output_data.is_null() {
output: if result.output_data.is_null() {
assert!(result.output_size == 0);
None
} else if result.output_size == 0 {
None
} else {
// Pre-allocate a vector.
let mut buf: Vec<u8> = Vec::with_capacity(result.output_size);
@ -363,8 +368,6 @@ impl From<ffi::evmc_result> for ExecutionResult {
}
Some(buf)
} else {
None
},
// Consider it is always valid.
create_address: Some(result.create_address),
@ -463,9 +466,9 @@ impl From<&ffi::evmc_message> for ExecutionMessage {
input: if message.input_data.is_null() {
assert!(message.input_size == 0);
None
} else if message.input_size == 0 {
None
} else {
// TODO: what to do if input_size is 0?
// Pre-allocate a vector.
let mut buf: Vec<u8> = Vec::with_capacity(message.input_size);