From 5b3333c6f5bcf5910dcd7eebbc4756d8e16318a4 Mon Sep 17 00:00:00 2001 From: Patrick Ventuzelo Date: Wed, 25 Sep 2019 21:52:45 +0200 Subject: [PATCH 1/2] fix unwrap by handling parse error --- src/bin/wasmer.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index cbbea3b6b..14d3caf26 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -514,17 +514,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .instantiate(&import_object) .map_err(|e| format!("Can't instantiate loader module: {:?}", e))?; - let args: Vec = options - .args - .iter() - .map(|arg| arg.as_str()) - .map(|x| { - Value::I32(x.parse().expect(&format!( + let mut args: Vec = Vec::new(); + for arg in options.args.iter() { + let x = arg.as_str().parse().map_err(|_| { + format!( "Can't parse the provided argument {:?} as a integer", - x - ))) - }) - .collect(); + arg.as_str() + ) + })?; + args.push(Value::I32(x)); + } + let index = instance .resolve_func("_start") .expect("The loader requires a _start function to be present in the module"); @@ -658,12 +658,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .instantiate(&import_object) .map_err(|e| format!("Can't instantiate module: {:?}", e))?; - let args: Vec = options - .args - .iter() - .map(|arg| arg.as_str()) - .map(|x| Value::I32(x.parse().unwrap())) - .collect(); + let mut args: Vec = Vec::new(); + for arg in options.args.iter() { + let x = arg.as_str().parse().map_err(|_| { + format!( + "Can't parse the provided argument {:?} as a integer", + arg.as_str() + ) + })?; + args.push(Value::I32(x)); + } + instance .dyn_func("main") .map_err(|e| format!("{:?}", e))? From 4b8d008f144bdc8415ced6669050aff93ff65451 Mon Sep 17 00:00:00 2001 From: Patrick Ventuzelo Date: Wed, 25 Sep 2019 21:53:18 +0200 Subject: [PATCH 2/2] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c91062936..0caae453f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#834](https://github.com/wasmerio/wasmer/pull/834) Fix panic when unwraping `wasmer` arguments - [#822](https://github.com/wasmerio/wasmer/pull/822) Update Cranelift fork version to `0.43.1` - [#829](https://github.com/wasmerio/wasmer/pull/829) Fix deps on `make bench-*` commands; benchmarks don't compile other backends now - [#807](https://github.com/wasmerio/wasmer/pull/807) Implement Send for `Instance`, breaking change on `ImportObject`, remove method `get_namespace` replaced with `with_namespace` and `maybe_with_namespace`