]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add assertion and ensure data has the correct type.
authorAlan T. DeKok <aland@freeradius.org>
Sun, 10 Jan 2021 20:07:52 +0000 (15:07 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 10 Jan 2021 21:14:11 +0000 (16:14 -0500)
because it has always been parsed as a real data type, we
no longer need / print a cast.

src/lib/server/cond_tokenize.c
src/lib/server/tmpl_tokenize.c
src/tests/unit/condition/base.txt

index b2b88abe1af2204b6eb5afcd76a864696cd359c5..fccd2a2dd73aa050492429186c6d8dda68a0f2c0 100644 (file)
@@ -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;
 }
 
index d54be2cafa9ced02539e799e2881ab73fb49d43c..ea1dbd901abb8de92bd4667f30745e827050134d 100644 (file)
@@ -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, "??"),
index 91df460f913cf270d457067a4070b9558cde12ed..23981183bcaeb083638ea8c463bf925a9f2ab89d 100644 (file)
@@ -233,22 +233,22 @@ condition <ipaddr>127.0.0.1 == "127.0.0.1"
 match true
 
 condition <ipaddr>127.0.0.1 == "%{md4: 127.0.0.1}"
-match <ipaddr>127.0.0.1 == "%{md4: 127.0.0.1}"
+match 127.0.0.1 == "%{md4: 127.0.0.1}"
 
 #
 #  Bare %{...} is allowed.
 #
 condition <ipaddr>127.0.0.1 == %{md4:127.0.0.1}
-match <ipaddr>127.0.0.1 == %{md4:127.0.0.1}
+match 127.0.0.1 == %{md4:127.0.0.1}
 
 condition <ipaddr>127.0.0.1 == %{md4: SELECT user FROM table WHERE user='%{User-Name}'}
-match <ipaddr>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 <ether> 00:11:22:33:44:55 == "00:11:22:33:44:55"
 match true
 
 condition <ether> 00:11:22:33:44:55 == "%{md4:00:11:22:33:44:55}"
-match <ether>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 <ether> 00:XX:22:33:44:55 == 00:11:22:33:44:55
 match ERROR offset 8: Failed parsing value as type 'ether'