From 52ea24f382199e1427d37b7e8fca46f6af220b74 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 9 Aug 2019 11:21:28 +0200 Subject: [PATCH] rust: enforce EVMC rules on message and result buffers --- bindings/rust/evmc-vm/src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bindings/rust/evmc-vm/src/lib.rs b/bindings/rust/evmc-vm/src/lib.rs index d3071dd..70c3910 100644 --- a/bindings/rust/evmc-vm/src/lib.rs +++ b/bindings/rust/evmc-vm/src/lib.rs @@ -351,7 +351,12 @@ impl From 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 = Vec::with_capacity(result.output_size); @@ -363,8 +368,6 @@ impl From 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 = Vec::with_capacity(message.input_size);