From: Alan T. DeKok Date: Tue, 6 Apr 2021 14:44:35 +0000 (-0400) Subject: arguments to "case" MUST be static data X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e67706262b76ff5a1fa22f515d1ea2575c8d6943;p=thirdparty%2Ffreeradius-server.git arguments to "case" MUST be static data in preparation for moving to rbtrees / hashes / patricia tries for "case" statement values --- diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 52d8b36267..c03d54375d 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -2107,42 +2107,20 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO return NULL; } - if (tmpl_is_attr_unresolved(vpt)) { - if (!pass2_fixup_tmpl(parent, cf_section_to_item(cs), &vpt)) { - talloc_free(vpt); - return NULL; - } - } - switch_g = unlang_generic_to_group(parent); switch_gext = unlang_group_to_switch(switch_g); fr_assert(switch_gext->vpt != NULL); /* - * 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 - * resolve it to the data type of the parent - * "switch" tmpl. + * This "case" statement is unresolved. Try to + * resolve it to the data type of the parent + * "switch" tmpl. */ if (tmpl_is_unresolved(vpt)) { fr_type_t cast_type = switch_gext->vpt->cast; fr_dict_attr_t const *da = NULL; - if (tmpl_is_attr(switch_gext->vpt)) da = tmpl_da(switch_gext->vpt); + if (tmpl_is_attr(switch_gext->vpt)) da = tmpl_da(switch_gext->vpt); if (fr_type_is_null(cast_type) && da) cast_type = da->type; @@ -2153,26 +2131,10 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO } } - /* - * Compile and sanity check xlat - * expansions. - */ - if (tmpl_is_xlat_unresolved(vpt)) { - /* - * Don't expand xlat's into an - * attribute of a different type. - */ - if (!pass2_fixup_tmpl(parent, cf_section_to_item(cs), &vpt)) { - talloc_free(vpt); - return NULL; - } - } - - if (tmpl_is_exec(vpt)) { - if (!pass2_fixup_tmpl(parent, cf_section_to_item(cs), &vpt)) { - talloc_free(vpt); - return NULL; - } + if (!tmpl_is_data(vpt)) { + talloc_free(vpt); + cf_log_err(cs, "arguments to 'case' statements MUST be static data."); + return NULL; } } /* else it's a default 'case' statement */ diff --git a/src/tests/keywords/switch b/src/tests/keywords/switch index d50e2f636e..5932accf85 100644 --- a/src/tests/keywords/switch +++ b/src/tests/keywords/switch @@ -9,7 +9,7 @@ switch &User-Name { } } - case { + default { update reply { &Filter-Id := "default" } diff --git a/src/tests/keywords/switch-attr-cast b/src/tests/keywords/switch-attr-cast deleted file mode 100644 index 7b6f383073..0000000000 --- a/src/tests/keywords/switch-attr-cast +++ /dev/null @@ -1,28 +0,0 @@ -# -# PRE: switch switch-attr-cmp -# - -update request { - &Service-Type := Login-User - &Filter-Id := "Login-User" -} - -switch &Service-Type { - case "%{expr: 1 + 2}" { - test_fail - } - - # - # The Filter-Id will get printed to a string, - # have the string parsed as a Service-Type attr, - # and then that compared to the input Service-Type - # - case &Filter-Id { - success - } - - default { - test_fail - } - -} diff --git a/src/tests/keywords/switch-attr-cmp b/src/tests/keywords/switch-attr-cmp deleted file mode 100644 index 1c1bf0d7cc..0000000000 --- a/src/tests/keywords/switch-attr-cmp +++ /dev/null @@ -1,28 +0,0 @@ -# -# PRE: switch -# -update request { - &Tmp-String-0 := &User-Name -} - -# -# A switch statement where we compare two attributes -# -switch &User-Name { - case &Tmp-String-0 { - success - } - - case "bob" { - test_fail - } - - case "doug" { - test_fail - } - - default { - test_fail - } - -} diff --git a/src/tests/keywords/switch-case-error b/src/tests/keywords/switch-case-error new file mode 100644 index 0000000000..c62dceb1f8 --- /dev/null +++ b/src/tests/keywords/switch-case-error @@ -0,0 +1,17 @@ +switch &User-Name { + case "%{Filter-Id}" { # ERROR + success + } + + case "doug" { + update reply { + &Filter-Id := "doug" + } + } + + default { + update reply { + &Filter-Id := "default" + } + } +} diff --git a/src/tests/keywords/switch-value-error b/src/tests/keywords/switch-value-error index e3cf1094f1..bb1fcfd37e 100644 --- a/src/tests/keywords/switch-value-error +++ b/src/tests/keywords/switch-value-error @@ -2,10 +2,6 @@ # PRE: switch # switch &Service-Type { - case "%{expr: 1 + 2}" { - test_fail - } - case Login-User { test_fail }