Skip to content

Commit

Permalink
EH: fix validation of delegate opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Jan 31, 2024
1 parent 43c4a5c commit c7dc14f
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -7128,6 +7128,30 @@ check_branch_block(WASMLoaderContext *loader_ctx, uint8 **p_buf, uint8 *buf_end,
return NULL;
}

#if WASM_ENABLE_EXCE_HANDLING != 0
static BranchBlock *
check_branch_block_for_delegate(WASMLoaderContext *loader_ctx, uint8 **p_buf,
uint8 *buf_end, char *error_buf,
uint32 error_buf_size)
{
uint8 *p = *p_buf, *p_end = buf_end;
BranchBlock *frame_csp_tmp;
uint32 depth;

read_leb_uint32(p, p_end, depth);
CHECK_BR(depth);
frame_csp_tmp = loader_ctx->frame_csp - depth - 2;
#if WASM_ENABLE_FAST_INTERP != 0
emit_br_info(frame_csp_tmp);
#endif

*p_buf = p;
return frame_csp_tmp;
fail:
return NULL;
}
#endif

static bool
check_block_stack(WASMLoaderContext *loader_ctx, BranchBlock *block,
char *error_buf, uint32 error_buf_size)
Expand Down Expand Up @@ -7830,16 +7854,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
case WASM_OP_DELEGATE:
{
/* check target block is valid */
if (!(frame_csp_tmp = check_branch_block(
if (!(frame_csp_tmp = check_branch_block_for_delegate(
loader_ctx, &p, p_end, error_buf, error_buf_size)))
goto fail;

/* valid types */
if (LABEL_TYPE_TRY != frame_csp_tmp->label_type) {
snprintf(error_buf, error_buf_size, "unknown label");
goto fail;
}

BranchBlock *cur_block = loader_ctx->frame_csp - 1;
uint8 label_type = cur_block->label_type;

Expand Down

0 comments on commit c7dc14f

Please sign in to comment.