From: Alan T. DeKok Date: Fri, 11 Sep 2015 13:18:33 +0000 (-0400) Subject: Syntax errors are errors, not assertions X-Git-Tag: release_3_0_10~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2acfc5b89e0e1a831f56e6708557087fa26c7eae;p=thirdparty%2Ffreeradius-server.git Syntax errors are errors, not assertions --- diff --git a/src/main/modcall.c b/src/main/modcall.c index 64f905d2b5f..ac6b4b6618b 100644 --- a/src/main/modcall.c +++ b/src/main/modcall.c @@ -2812,9 +2812,18 @@ static modcallable *do_compile_modgroup(modcallable *parent, rad_assert(p->tail != NULL); + /* + * We're in the process of compiling the + * section, so the parent's tail is the + * previous "if" statement. + */ f = mod_callabletogroup(p->tail); - rad_assert((f->mc.type == MOD_IF) || - (f->mc.type == MOD_ELSIF)); + if ((f->mc.type != MOD_IF) && + (f->mc.type != MOD_ELSIF)) { + cf_log_err_cs(g->cs, "Invalid location for 'elsif'. There is no preceding 'if' statement"); + talloc_free(g); + return NULL; + } /* * If we took the previous condition, we @@ -2844,8 +2853,12 @@ static modcallable *do_compile_modgroup(modcallable *parent, rad_assert(p->tail != NULL); f = mod_callabletogroup(p->tail); - rad_assert((f->mc.type == MOD_IF) || - (f->mc.type == MOD_ELSIF)); + if ((f->mc.type != MOD_IF) && + (f->mc.type != MOD_ELSIF)) { + cf_log_err_cs(g->cs, "Invalid location for 'else'. There is no preceding 'if' statement"); + talloc_free(g); + return NULL; + } /* * If we took the previous condition, we diff --git a/src/tests/keywords/else-error b/src/tests/keywords/else-error new file mode 100644 index 00000000000..3816270ecda --- /dev/null +++ b/src/tests/keywords/else-error @@ -0,0 +1,14 @@ +# +# PRE: update if +# +# "else" has to be preceded by an "if" or "elsif" +# +if (1) { + update reply { + Filter-Id := "filter" + } + + else { # ERROR + ok + } +}