Refine wgl lib and refine wasm function index check (#122)

Refine wgl lib: remove module_inst parameter from widget functions
Refine wasm function check: move function index check from interpreter call_indirect to runtime instantiate
This commit is contained in:
wenyongh
2019-09-16 14:49:17 +08:00
committed by GitHub
parent ff0267b7e6
commit 6e99a37bf2
9 changed files with 65 additions and 41 deletions

View File

@ -880,11 +880,8 @@ wasm_interp_call_func_bytecode(WASMThread *self,
}
fidx = ((uint32*)table->base_addr)[val];
if (fidx >= module->function_count) {
wasm_runtime_set_exception(module, "function index is overflow");
goto got_exception;
}
/* Skip function index check, it has been checked
in wasm module instantiate */
cur_func = module->functions + fidx;
if (cur_func->is_import_func)

View File

@ -741,7 +741,7 @@ wasm_runtime_instantiate(WASMModule *module,
WASMTableSeg *table_seg;
WASMDataSeg *data_seg;
WASMGlobalInstance *globals = NULL, *global;
uint32 global_count, addr_data_size = 0, global_data_size = 0, i;
uint32 global_count, addr_data_size = 0, global_data_size = 0, i, j;
uint32 base_offset, length, memory_size;
uint8 *global_data, *global_data_end, *addr_data, *addr_data_end;
uint8 *memory_data;
@ -927,6 +927,15 @@ wasm_runtime_instantiate(WASMModule *module,
module_inst->default_table->cur_size)
length = module_inst->default_table->cur_size
- table_seg->base_offset.u.i32;
/* Check function index */
for (j = 0; j < length; j++) {
if (table_seg->func_indexes[j] >= module_inst->function_count) {
set_error_buf(error_buf, error_buf_size,
"function index is overflow");
wasm_runtime_deinstantiate(module_inst);
return NULL;
}
}
memcpy(table_data + table_seg->base_offset.u.i32,
table_seg->func_indexes, length * sizeof(uint32));
}
@ -1618,9 +1627,9 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
break;
case VALUE_TYPE_F32:
if (n_fps < MAX_REG_FLOATS)
*(float64*)&fps[n_fps++] = *(float32*)argv_src++;
*(float32*)&fps[n_fps++] = *(float32*)argv_src++;
else
*(float64*)&stacks[n_stacks++] = *(float32*)argv_src++;
*(float32*)&stacks[n_stacks++] = *(float32*)argv_src++;
break;
case VALUE_TYPE_F64:
if (n_fps < MAX_REG_FLOATS)