From 5cda9a05dad8bdf18d0ad0c83159b576f6e20c7d Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Wed, 18 Apr 2018 17:44:10 +0300 Subject: [PATCH] Check the signature of host function. (#84) --- src/runner.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/runner.rs b/src/runner.rs index 15ec910..f075d21 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -107,6 +107,14 @@ impl<'a, E: Externals> Interpreter<'a, E> { FuncInstanceInternal::Host { ref signature, .. } => { let args = prepare_function_args(signature, &mut function_context.value_stack); let return_val = FuncInstance::invoke(&nested_func, &args, self.externals)?; + + // Check if `return_val` matches the signature. + let value_ty = return_val.clone().map(|val| val.value_type()); + let expected_ty = nested_func.signature().return_type(); + if value_ty != expected_ty { + return Err(TrapKind::UnexpectedSignature.into()); + } + if let Some(return_val) = return_val { function_context.value_stack_mut().push(return_val).map_err(Trap::new)?; }