]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
forbid list / regex for switch / case
authorAlan T. DeKok <aland@freeradius.org>
Tue, 12 Jan 2021 13:13:27 +0000 (08:13 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 12 Jan 2021 20:49:51 +0000 (15:49 -0500)
we can _probably_ allow regexes for case, but that requires
additional changes to switch.c.  The condition created there
must satisfy the requirements of the run-time evaluator

src/lib/unlang/compile.c

index 492451ce7639bc81cd6547d8f2db66c81004f017..273f59cdea38556cbf108b6aabe5ecb7c969178e 100644 (file)
@@ -1953,6 +1953,18 @@ static unlang_t *compile_switch(UNUSED unlang_t *parent, unlang_compile_t *unlan
                return NULL;
        }
 
+       if (tmpl_is_list(gext->vpt)) {
+               cf_log_err(cs, "Cannot use list for 'switch' statement");
+               talloc_free(g);
+               return NULL;
+       }
+
+       if (tmpl_contains_regex(gext->vpt)) {
+               cf_log_err(cs, "Cannot use regular expression for 'switch' statement");
+               talloc_free(g);
+               return NULL;
+       }
+
        if (!tmpl_is_attr(gext->vpt)) (void) tmpl_cast_set(gext->vpt, FR_TYPE_STRING);
 
        /*
@@ -2099,6 +2111,17 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO
                /*
                 *      Do type-specific checks on the case statement
                 */
+               if (tmpl_is_list(vpt)) {
+                       cf_log_perr(cs, "Cannot use list for target of 'case' statement");
+                       talloc_free(vpt);
+                       return NULL;
+               }
+
+               if (tmpl_contains_regex(vpt)) {
+                       cf_log_err(cs, "Cannot use regular expression for target of 'case' statement");
+                       talloc_free(vpt);
+                       return NULL;
+               }
 
                /*
                 *      This "case" statement is unresolved.  Try to
@@ -2114,7 +2137,7 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO
                        if ((cast_type == FR_TYPE_INVALID) && da) cast_type = da->type;
 
                        if (tmpl_cast_in_place(vpt, cast_type, da) < 0) {
-                               cf_log_perr(cs, "Invalid argument for case statement");
+                               cf_log_perr(cs, "Invalid argument for 'case' statement");
                                talloc_free(vpt);
                                return NULL;
                        }