]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Syntax errors are errors, not assertions
authorAlan T. DeKok <aland@freeradius.org>
Fri, 11 Sep 2015 13:18:33 +0000 (09:18 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 11 Sep 2015 13:19:29 +0000 (09:19 -0400)
src/main/modcall.c
src/tests/keywords/else-error [new file with mode: 0644]

index 64f905d2b5f9c9f42aae14f953f46eafe4488b17..ac6b4b6618b23921ea14f481f1db6c3ace06285d 100644 (file)
@@ -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 (file)
index 0000000..3816270
--- /dev/null
@@ -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
+       }
+}