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 loader check_wasi_abi_compatibility #3126

Merged
merged 1 commit into from
Feb 4, 2024
Merged
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
28 changes: 21 additions & 7 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4267,14 +4267,22 @@ check_wasi_abi_compatibility(const WASMModule *module,
/* clang-format on */

WASMExport *initialize = NULL, *memory = NULL, *start = NULL;
uint32 import_function_count = module->import_function_count;
WASMType *func_type;

/* (func (export "_start") (...) */
start = wasm_loader_find_export(module, "", "_start", EXPORT_KIND_FUNC,
error_buf, error_buf_size);
if (start) {
WASMType *func_type =
module->functions[start->index - module->import_function_count]
->func_type;
if (start->index < import_function_count) {
set_error_buf(
error_buf, error_buf_size,
"the builtin _start function can not be an import function");
return false;
}

func_type =
module->functions[start->index - import_function_count]->func_type;
if (func_type->param_count || func_type->result_count) {
set_error_buf(error_buf, error_buf_size,
"the signature of builtin _start function is wrong");
Expand All @@ -4286,11 +4294,17 @@ check_wasi_abi_compatibility(const WASMModule *module,
initialize =
wasm_loader_find_export(module, "", "_initialize", EXPORT_KIND_FUNC,
error_buf, error_buf_size);

if (initialize) {
WASMType *func_type =
module
->functions[initialize->index
- module->import_function_count]
if (initialize->index < import_function_count) {
set_error_buf(error_buf, error_buf_size,
"the builtin _initialize function can not be an "
"import function");
return false;
}

func_type =
module->functions[initialize->index - import_function_count]
->func_type;
if (func_type->param_count || func_type->result_count) {
set_error_buf(
Expand Down