Skip to content

Commit 06df58f

Browse files
authored
Fix loader check_wasi_abi_compatibility (#3126)
Assume that wasi exported `_start` and `_initialize` functions can not be an import function. Fixes issue #3122.
1 parent 529fa9d commit 06df58f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

core/iwasm/interpreter/wasm_loader.c

+21-7
Original file line numberDiff line numberDiff line change
@@ -4267,14 +4267,22 @@ check_wasi_abi_compatibility(const WASMModule *module,
42674267
/* clang-format on */
42684268

42694269
WASMExport *initialize = NULL, *memory = NULL, *start = NULL;
4270+
uint32 import_function_count = module->import_function_count;
4271+
WASMType *func_type;
42704272

42714273
/* (func (export "_start") (...) */
42724274
start = wasm_loader_find_export(module, "", "_start", EXPORT_KIND_FUNC,
42734275
error_buf, error_buf_size);
42744276
if (start) {
4275-
WASMType *func_type =
4276-
module->functions[start->index - module->import_function_count]
4277-
->func_type;
4277+
if (start->index < import_function_count) {
4278+
set_error_buf(
4279+
error_buf, error_buf_size,
4280+
"the builtin _start function can not be an import function");
4281+
return false;
4282+
}
4283+
4284+
func_type =
4285+
module->functions[start->index - import_function_count]->func_type;
42784286
if (func_type->param_count || func_type->result_count) {
42794287
set_error_buf(error_buf, error_buf_size,
42804288
"the signature of builtin _start function is wrong");
@@ -4286,11 +4294,17 @@ check_wasi_abi_compatibility(const WASMModule *module,
42864294
initialize =
42874295
wasm_loader_find_export(module, "", "_initialize", EXPORT_KIND_FUNC,
42884296
error_buf, error_buf_size);
4297+
42894298
if (initialize) {
4290-
WASMType *func_type =
4291-
module
4292-
->functions[initialize->index
4293-
- module->import_function_count]
4299+
if (initialize->index < import_function_count) {
4300+
set_error_buf(error_buf, error_buf_size,
4301+
"the builtin _initialize function can not be an "
4302+
"import function");
4303+
return false;
4304+
}
4305+
4306+
func_type =
4307+
module->functions[initialize->index - import_function_count]
42944308
->func_type;
42954309
if (func_type->param_count || func_type->result_count) {
42964310
set_error_buf(

0 commit comments

Comments
 (0)