@@ -4267,14 +4267,22 @@ check_wasi_abi_compatibility(const WASMModule *module,
4267
4267
/* clang-format on */
4268
4268
4269
4269
WASMExport * initialize = NULL , * memory = NULL , * start = NULL ;
4270
+ uint32 import_function_count = module -> import_function_count ;
4271
+ WASMType * func_type ;
4270
4272
4271
4273
/* (func (export "_start") (...) */
4272
4274
start = wasm_loader_find_export (module , "" , "_start" , EXPORT_KIND_FUNC ,
4273
4275
error_buf , error_buf_size );
4274
4276
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 ;
4278
4286
if (func_type -> param_count || func_type -> result_count ) {
4279
4287
set_error_buf (error_buf , error_buf_size ,
4280
4288
"the signature of builtin _start function is wrong" );
@@ -4286,11 +4294,17 @@ check_wasi_abi_compatibility(const WASMModule *module,
4286
4294
initialize =
4287
4295
wasm_loader_find_export (module , "" , "_initialize" , EXPORT_KIND_FUNC ,
4288
4296
error_buf , error_buf_size );
4297
+
4289
4298
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 ]
4294
4308
-> func_type ;
4295
4309
if (func_type -> param_count || func_type -> result_count ) {
4296
4310
set_error_buf (
0 commit comments