Skip to content

Commit

Permalink
EH: Don't call word_copy with zero size (bytecodealliance#3105)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt authored Jan 31, 2024
1 parent 43c4a5c commit 10e87d2
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,18 +1387,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
/* push exception_tag_index and
* exception values for rethrow */
PUSH_I32(exception_tag_index);
word_copy(frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
/* push exception values for catch
*/
word_copy(frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
if (cell_num_to_copy > 0) {
word_copy(
frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
/* push exception values for
* catch
*/
word_copy(
frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
}

/* advance to handler */
HANDLE_OP_END();
Expand Down Expand Up @@ -1427,11 +1432,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
frame_csp -= lookup_depth;

/* push exception values for catch */
word_copy(frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
if (cell_num_to_copy > 0) {
word_copy(frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
}

/* tag_index is already stored in
* exception_tag_index */
Expand All @@ -1452,11 +1459,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
/* push exception_tag_index and
* exception values for rethrow */
PUSH_I32(exception_tag_index);
word_copy(frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
if (cell_num_to_copy > 0) {
word_copy(frame_sp,
frame_sp_old
- cell_num_to_copy,
cell_num_to_copy);
frame_sp += cell_num_to_copy;
}
/* catch_all has no exception values */

/* advance to handler */
Expand All @@ -1483,10 +1492,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
* The values are copied to the CALLER FRAME
* (prev_frame->sp) same behvior ad WASM_OP_RETURN
*/
word_copy(prev_frame->sp,
frame_sp_old - cell_num_to_copy,
cell_num_to_copy);
prev_frame->sp += cell_num_to_copy;
if (cell_num_to_copy > 0) {
word_copy(prev_frame->sp,
frame_sp_old - cell_num_to_copy,
cell_num_to_copy);
prev_frame->sp += cell_num_to_copy;
}
*((int32 *)(prev_frame->sp)) = exception_tag_index;
prev_frame->sp++;

Expand Down

0 comments on commit 10e87d2

Please sign in to comment.