Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 800 - check index before accessing imports.globals #809

Merged
merged 3 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments.

## **[Unreleased]**

- [#809](https://github.com/wasmerio/wasmer/pull/809) Fix bugs leading to panics in `LocalBacking`.
- [#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`
Expand Down
20 changes: 20 additions & 0 deletions lib/runtime-core/src/backing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ impl LocalBacking {
}]);
}
Initializer::GetGlobal(import_global_index) => {
if import_global_index.index() >= imports.globals.len() {
return Err(vec![LinkError::Generic {
message: "incorrect global index for initializer".to_string(),
}]);
}
if let Value::I32(x) = imports.globals[import_global_index].get() {
x as u32
} else {
Expand Down Expand Up @@ -208,6 +213,11 @@ impl LocalBacking {
}]);
}
Initializer::GetGlobal(import_global_index) => {
if import_global_index.index() >= imports.globals.len() {
return Err(vec![LinkError::Generic {
message: "incorrect global index for initializer".to_string(),
}]);
}
if let Value::I32(x) = imports.globals[import_global_index].get() {
x as u32
} else {
Expand Down Expand Up @@ -276,6 +286,11 @@ impl LocalBacking {
}]);
}
Initializer::GetGlobal(import_global_index) => {
if import_global_index.index() >= imports.globals.len() {
return Err(vec![LinkError::Generic {
message: "incorrect global index for initializer".to_string(),
}]);
}
if let Value::I32(x) = imports.globals[import_global_index].get() {
x as u32
} else {
Expand Down Expand Up @@ -329,6 +344,11 @@ impl LocalBacking {
}]);
}
Initializer::GetGlobal(import_global_index) => {
if import_global_index.index() >= imports.globals.len() {
return Err(vec![LinkError::Generic {
message: "incorrect global index for initializer".to_string(),
}]);
}
if let Value::I32(x) = imports.globals[import_global_index].get() {
x as u32
} else {
Expand Down