@@ -7128,6 +7128,40 @@ check_branch_block(WASMLoaderContext *loader_ctx, uint8 **p_buf, uint8 *buf_end,
71287128 return NULL ;
71297129}
71307130
7131+ #if WASM_ENABLE_EXCE_HANDLING != 0
7132+ static BranchBlock *
7133+ check_branch_block_for_delegate (WASMLoaderContext * loader_ctx , uint8 * * p_buf ,
7134+ uint8 * buf_end , char * error_buf ,
7135+ uint32 error_buf_size )
7136+ {
7137+ uint8 * p = * p_buf , * p_end = buf_end ;
7138+ BranchBlock * frame_csp_tmp ;
7139+ uint32 depth ;
7140+
7141+ read_leb_uint32 (p , p_end , depth );
7142+ /*
7143+ * Note: "delegate 0" means the surrounding block, not the
7144+ * try-delegate block itself.
7145+ *
7146+ * Note: the caller hasn't popped the try-delegate frame yet.
7147+ */
7148+ bh_assert (loader_ctx -> csp_num > 0 );
7149+ if (loader_ctx -> csp_num - 1 <= depth ) {
7150+ set_error_buf (error_buf , error_buf_size , "unknown delegate label" );
7151+ goto fail ;
7152+ }
7153+ frame_csp_tmp = loader_ctx -> frame_csp - depth - 2 ;
7154+ #if WASM_ENABLE_FAST_INTERP != 0
7155+ emit_br_info (frame_csp_tmp );
7156+ #endif
7157+
7158+ * p_buf = p ;
7159+ return frame_csp_tmp ;
7160+ fail :
7161+ return NULL ;
7162+ }
7163+ #endif
7164+
71317165static bool
71327166check_block_stack (WASMLoaderContext * loader_ctx , BranchBlock * block ,
71337167 char * error_buf , uint32 error_buf_size )
@@ -7832,16 +7866,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
78327866 case WASM_OP_DELEGATE :
78337867 {
78347868 /* check target block is valid */
7835- if (!(frame_csp_tmp = check_branch_block (
7869+ if (!(frame_csp_tmp = check_branch_block_for_delegate (
78367870 loader_ctx , & p , p_end , error_buf , error_buf_size )))
78377871 goto fail ;
78387872
7839- /* valid types */
7840- if (LABEL_TYPE_TRY != frame_csp_tmp -> label_type ) {
7841- snprintf (error_buf , error_buf_size , "unknown label" );
7842- goto fail ;
7843- }
7844-
78457873 BranchBlock * cur_block = loader_ctx -> frame_csp - 1 ;
78467874 uint8 label_type = cur_block -> label_type ;
78477875
0 commit comments