Redundant, load-balance, etc. can't be empty
authorAlan T. DeKok <aland@freeradius.org>
Tue, 10 Jun 2014 14:28:21 +0000 (10:28 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 10 Jun 2014 14:36:13 +0000 (10:36 -0400)
src/main/modcall.c
src/tests/keywords/redundant-error [new file with mode: 0644]

index 3aee518..701e22e 100644 (file)
@@ -899,6 +899,8 @@ redo:
 
                g = mod_callabletogroup(c);
                found = NULL;
+               rad_assert(g->children != NULL);
+
                for (this = g->children; this; this = this->next) {
                        if (!found) {
                                found = this;
@@ -2503,7 +2505,8 @@ static modcallable *do_compile_modgroup(modcallable *parent,
        c->name = cf_section_name2(cs);
        if (!c->name) {
                c->name = cf_section_name1(cs);
-               if (strcmp(c->name, "group") == 0) {
+               if ((strcmp(c->name, "group") == 0) ||
+                   (strcmp(c->name, "redundant") == 0)) {
                        c->name = "";
                } else if (c->type == MOD_GROUP) {
                        c->type = MOD_POLICY;
@@ -2678,6 +2681,24 @@ set_codes:
                }
        }
 
+       switch (c->type) {
+       default:
+               break;
+
+       case MOD_GROUP:
+               if (grouptype != GROUPTYPE_REDUNDANT) break;
+               /* FALL-THROUGH */
+
+       case MOD_LOAD_BALANCE:
+       case MOD_REDUNDANT_LOAD_BALANCE:
+               if (!g->children) {
+                       cf_log_err_cs(g->cs, "%s sections cannot be empty",
+                                     cf_section_name1(g->cs));
+                       modcallable_free(&c);
+                       return NULL;
+               }
+       }
+
        /*
         *      FIXME: If there are no children, return NULL?
         */
diff --git a/src/tests/keywords/redundant-error b/src/tests/keywords/redundant-error
new file mode 100644 (file)
index 0000000..bec4335
--- /dev/null
@@ -0,0 +1,6 @@
+#
+#  Check that redundant blocks can't be empty
+#
+redundant {    # ERROR
+
+}