fix(runtime-core) Fix a panic when generating globals.

Fix https://github.com/wasmerio/wasmer/issues/979.

When we try to get a global that doesn't exist, a panic is
generated. This patch just skip that path, and let a proper error be
generated later.

With this patch, we get:

```sh
$ cargo run -- run panic_index_oob_all_backends.wasm
Error: ExportNotFound { name: "main" }
```

which is kind of the expected behavior in such situation.
This commit is contained in:
Ivan Enderlin 2019-11-21 10:51:04 +01:00
parent 8efa8e299c
commit a9e446b5cd

View File

@ -450,6 +450,11 @@ impl LocalBacking {
let value = match &global_init.init {
Initializer::Const(value) => value.clone(),
Initializer::GetGlobal(import_global_index) => {
// Skip if the global hasn't been initialized properly.
if imports.globals.len() <= import_global_index.index() {
continue;
}
imports.globals[*import_global_index].get()
}
};