0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 12:48:43 +00:00

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.
This commit is contained in:
Ondrej Zajicek (work) 2020-12-28 15:23:28 +01:00
parent 61dae32b29
commit 9e2635505a

View File

@ -922,18 +922,17 @@
uint retpos = fstk->vcnt; uint retpos = fstk->vcnt;
/* Drop every sub-block including ourselves */ /* 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. */ /* Now we are at the caller frame; if no such, try to convert to accept/reject. */
if (!fstk->ecnt) if (!fstk->ecnt)
{
if (fstk->vstk[retpos].type == T_BOOL) if (fstk->vstk[retpos].type == T_BOOL)
if (fstk->vstk[retpos].val.i) return (fstk->vstk[retpos].val.i) ? F_ACCEPT : F_REJECT;
return F_ACCEPT;
else
return F_REJECT;
else else
runtime("Can't return non-bool from non-function"); runtime("Can't return non-bool from non-function");
}
/* Set the value stack position, overwriting the former implicit void */ /* Set the value stack position, overwriting the former implicit void */
fstk->vcnt = fstk->estk[fstk->ecnt].ventry - 1; fstk->vcnt = fstk->estk[fstk->ecnt].ventry - 1;