]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Fix return on top-level
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 28 Dec 2020 14:23:28 +0000 (15:23 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 28 Dec 2020 14:23:28 +0000 (15:23 +0100)
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

index 58717d558556c0e48415f32f64a9364bd4f3f7b0..b6bc81f7bd15e704518464734a2de848960173ea 100644 (file)
     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;