Skip to content

Commit 33acce2

Browse files
committed
Added missing boundary checks on pop() and pick()
1 parent 367d98f commit 33acce2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/zforth/zforth.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ zf_cell zf_pop(zf_ctx *ctx)
169169
{
170170
zf_cell v;
171171
CHECK(ctx, DSP(ctx) > 0, ZF_ABORT_DSTACK_UNDERRUN);
172+
CHECK(ctx, DSP(ctx) < ZF_DSTACK_SIZE, ZF_ABORT_DSTACK_OVERRUN);
172173
v = ctx->dstack[--DSP(ctx)];
173174
trace(ctx, "«" ZF_CELL_FMT " ", v);
174175
return v;
@@ -178,6 +179,7 @@ zf_cell zf_pop(zf_ctx *ctx)
178179
zf_cell zf_pick(zf_ctx *ctx, zf_addr n)
179180
{
180181
CHECK(ctx, n < DSP(ctx), ZF_ABORT_DSTACK_UNDERRUN);
182+
CHECK(ctx, DSP(ctx) < ZF_DSTACK_SIZE, ZF_ABORT_DSTACK_OVERRUN);
181183
return ctx->dstack[DSP(ctx)-n-1];
182184
}
183185

@@ -194,6 +196,7 @@ static zf_cell zf_popr(zf_ctx *ctx)
194196
{
195197
zf_cell v;
196198
CHECK(ctx, RSP(ctx) > 0, ZF_ABORT_RSTACK_UNDERRUN);
199+
CHECK(ctx, RSP(ctx) < ZF_RSTACK_SIZE, ZF_ABORT_RSTACK_OVERRUN);
197200
v = ctx->rstack[--RSP(ctx)];
198201
trace(ctx, "r«" ZF_CELL_FMT " ", v);
199202
return v;
@@ -202,6 +205,7 @@ static zf_cell zf_popr(zf_ctx *ctx)
202205
zf_cell zf_pickr(zf_ctx *ctx, zf_addr n)
203206
{
204207
CHECK(ctx, n < RSP(ctx), ZF_ABORT_RSTACK_UNDERRUN);
208+
CHECK(ctx, RSP(ctx) < ZF_RSTACK_SIZE, ZF_ABORT_RSTACK_OVERRUN);
205209
return ctx->rstack[RSP(ctx)-n-1];
206210
}
207211

0 commit comments

Comments
 (0)