Skip to content

Commit 0ecaf8c

Browse files
authored
add validation of dynamic_offset (#4563)
* add check_dynamic_offset_pop
1 parent 3bf08a0 commit 0ecaf8c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8542,6 +8542,15 @@ check_offset_pop(WASMLoaderContext *ctx, uint32 cells)
85428542
return true;
85438543
}
85448544

8545+
static bool
8546+
check_dynamic_offset_pop(WASMLoaderContext *ctx, uint32 cells)
8547+
{
8548+
if (ctx->dynamic_offset < 0
8549+
|| (ctx->dynamic_offset > 0 && (uint32)ctx->dynamic_offset < cells))
8550+
return false;
8551+
return true;
8552+
}
8553+
85458554
static void
85468555
free_label_patch_list(BranchBlock *frame_csp)
85478556
{
@@ -9980,7 +9989,8 @@ wasm_loader_pop_frame_offset(WASMLoaderContext *ctx, uint8 type,
99809989
return true;
99819990

99829991
ctx->frame_offset -= cell_num_to_pop;
9983-
if ((*(ctx->frame_offset) > ctx->start_dynamic_offset)
9992+
if (check_dynamic_offset_pop(ctx, cell_num_to_pop)
9993+
&& (*(ctx->frame_offset) > ctx->start_dynamic_offset)
99849994
&& (*(ctx->frame_offset) < ctx->max_dynamic_offset))
99859995
ctx->dynamic_offset -= cell_num_to_pop;
99869996

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4342,6 +4342,15 @@ check_offset_pop(WASMLoaderContext *ctx, uint32 cells)
43424342
return true;
43434343
}
43444344

4345+
static bool
4346+
check_dynamic_offset_pop(WASMLoaderContext *ctx, uint32 cells)
4347+
{
4348+
if (ctx->dynamic_offset < 0
4349+
|| (ctx->dynamic_offset > 0 && (uint32)ctx->dynamic_offset < cells))
4350+
return false;
4351+
return true;
4352+
}
4353+
43454354
static void
43464355
free_label_patch_list(BranchBlock *frame_csp)
43474356
{
@@ -5256,7 +5265,8 @@ wasm_loader_pop_frame_offset(WASMLoaderContext *ctx, uint8 type,
52565265
return true;
52575266

52585267
ctx->frame_offset -= cell_num_to_pop;
5259-
if ((*(ctx->frame_offset) > ctx->start_dynamic_offset)
5268+
if (check_dynamic_offset_pop(ctx, cell_num_to_pop)
5269+
&& (*(ctx->frame_offset) > ctx->start_dynamic_offset)
52605270
&& (*(ctx->frame_offset) < ctx->max_dynamic_offset))
52615271
ctx->dynamic_offset -= cell_num_to_pop;
52625272

0 commit comments

Comments
 (0)