From: Alan T. DeKok Date: Sun, 10 Jan 2021 20:07:52 +0000 (-0500) Subject: add assertion and ensure data has the correct type. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb94fc7963d87f26b2b5dd7d23986dfe213e66d1;p=thirdparty%2Ffreeradius-server.git add assertion and ensure data has the correct type. because it has always been parsed as a real data type, we no longer need / print a cast. --- diff --git a/src/lib/server/cond_tokenize.c b/src/lib/server/cond_tokenize.c index b2b88abe1af..fccd2a2dd73 100644 --- a/src/lib/server/cond_tokenize.c +++ b/src/lib/server/cond_tokenize.c @@ -221,6 +221,13 @@ static int cond_cast_tmpl(tmpl_t *vpt, fr_type_t *p_type, tmpl_t *other) return -1; } + /* + * The result has to be data, AND of the correct type. + * Which means we no longer need the cast. + */ + fr_assert(tmpl_is_data(vpt)); + fr_assert((vpt->cast == FR_TYPE_INVALID) || (vpt->cast == tmpl_value_type(vpt))); + (void) tmpl_cast_set(vpt, FR_TYPE_INVALID); return 0; } diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index d54be2cafa9..ea1dbd901ab 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -2845,11 +2845,6 @@ int tmpl_cast_set(tmpl_t *vpt, fr_type_t dst_type) case TMPL_TYPE_DATA: src_type = tmpl_value_type(vpt); - - /* - * Don't suppress duplicate casts for now, the - * conditional parser still needs them. - */ goto check_types; case TMPL_TYPE_ATTR: @@ -2859,12 +2854,12 @@ int tmpl_cast_set(tmpl_t *vpt, fr_type_t dst_type) /* * Suppress casts where they are duplicate. */ + check_types: if (src_type == dst_type) { vpt->cast = FR_TYPE_INVALID; return 0; } - check_types: if (!fr_type_cast(dst_type, src_type)) { fr_strerror_printf("Cannot cast type '%s' to '%s'", fr_table_str_by_value(fr_value_box_type_table, src_type, "??"), diff --git a/src/tests/unit/condition/base.txt b/src/tests/unit/condition/base.txt index 91df460f913..23981183bca 100644 --- a/src/tests/unit/condition/base.txt +++ b/src/tests/unit/condition/base.txt @@ -233,22 +233,22 @@ condition 127.0.0.1 == "127.0.0.1" match true condition 127.0.0.1 == "%{md4: 127.0.0.1}" -match 127.0.0.1 == "%{md4: 127.0.0.1}" +match 127.0.0.1 == "%{md4: 127.0.0.1}" # # Bare %{...} is allowed. # condition 127.0.0.1 == %{md4:127.0.0.1} -match 127.0.0.1 == %{md4:127.0.0.1} +match 127.0.0.1 == %{md4:127.0.0.1} condition 127.0.0.1 == %{md4: SELECT user FROM table WHERE user='%{User-Name}'} -match 127.0.0.1 == %{md4: SELECT user FROM table WHERE user='%{User-Name}'} +match 127.0.0.1 == %{md4: SELECT user FROM table WHERE user='%{User-Name}'} condition 00:11:22:33:44:55 == "00:11:22:33:44:55" match true condition 00:11:22:33:44:55 == "%{md4:00:11:22:33:44:55}" -match 00:11:22:33:44:55 == "%{md4:00:11:22:33:44:55}" +match 00:11:22:33:44:55 == "%{md4:00:11:22:33:44:55}" condition 00:XX:22:33:44:55 == 00:11:22:33:44:55 match ERROR offset 8: Failed parsing value as type 'ether'