From 9e2635505a08e3453eef487360e49b4b70987ceb Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Mon, 28 Dec 2020 15:23:28 +0100 Subject: Filter: Fix return on top-level Broken detection of top-level case caused crash when return was called from top-of-stack position. It should behave as reject/accept. Thanks to Damian Zaremba for the bugreport. --- filter/f-inst.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/filter/f-inst.c b/filter/f-inst.c index 58717d55..b6bc81f7 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -922,18 +922,17 @@ uint retpos = fstk->vcnt; /* Drop every sub-block including ourselves */ - while ((fstk->ecnt-- > 0) && !(fstk->estk[fstk->ecnt].emask & FE_RETURN)) - ; + do fstk->ecnt--; + while ((fstk->ecnt > 0) && !(fstk->estk[fstk->ecnt].emask & FE_RETURN)); /* Now we are at the caller frame; if no such, try to convert to accept/reject. */ if (!fstk->ecnt) + { if (fstk->vstk[retpos].type == T_BOOL) - if (fstk->vstk[retpos].val.i) - return F_ACCEPT; - else - return F_REJECT; + return (fstk->vstk[retpos].val.i) ? F_ACCEPT : F_REJECT; else runtime("Can't return non-bool from non-function"); + } /* Set the value stack position, overwriting the former implicit void */ fstk->vcnt = fstk->estk[fstk->ecnt].ventry - 1; -- cgit v1.2.3