]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
have tmpl_cast_set() call fr_type_cast()
authorAlan T. DeKok <aland@freeradius.org>
Fri, 8 Jan 2021 14:50:21 +0000 (09:50 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 9 Jan 2021 20:02:15 +0000 (15:02 -0500)
and update tests to match.

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

index 919052122b90eef52e98c67d03ea3fc6331aa24c..d54be2cafa9ced02539e799e2881ab73fb49d43c 100644 (file)
@@ -2865,52 +2865,13 @@ int tmpl_cast_set(tmpl_t *vpt, fr_type_t dst_type)
                }
 
        check_types:
-               /*
-                *      Anything can be cast to a string or octets.
-                */
-               if ((dst_type == FR_TYPE_STRING) || (dst_type == FR_TYPE_OCTETS)) {
-                       break;
-               }
-
-               /*
-                *      Integers, dates, etc. can all be cast to each
-                *      other.  We will do run-time checks to see if
-                *      the _values_ being cast fit within the
-                *      permitted data types.
-                */
-               if ((src_type >= FR_TYPE_BOOL) && (dst_type >= FR_TYPE_BOOL)) {
-                       break;
-               }
-
-               /*
-                *      IP address types can be cast to each other.
-                *
-                *      IP addresses can also be cast to some integers,
-                *      but we don't check for that.
-                */
-               if (((src_type >= FR_TYPE_IPV4_ADDR) && (dst_type >= FR_TYPE_IPV4_ADDR)) &&
-                   ((src_type <= FR_TYPE_IPV6_PREFIX) && (dst_type <= FR_TYPE_IPV6_PREFIX))) {
-                       break;
-               }
-
-               /*
-                *      IFID / Ethernet can only be cast to uint64.
-                *
-                *      Note that we already check for dst_type of string/octets above.
-                */
-               if (((src_type == FR_TYPE_IFID) || (src_type == FR_TYPE_IFID)) && (dst_type != FR_TYPE_UINT64)) {
+               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, "??"),
                                           fr_table_str_by_value(fr_value_box_type_table, dst_type, "??"));
                        return -1;
                }
-
-               /*
-                *      Other casts MAY be forbidden, but we don't
-                *      bother checking those here.  :(
-                */
                break;
-
        }
 
 done:
index fb94d59a37f37f976c7cee13df9fc3d647bc7537..b45c81635914835723b5b60ad5b89644662fcd3f 100644 (file)
@@ -425,7 +425,7 @@ match &Tmp-Integer64-0 == &reply.Foo-Stuff-Bar
 #  Casting attributes of different size
 #
 condition <ipaddr>&Tmp-Integer64-0 == &Framed-IP-Address
-match ERROR offset 0: Cannot cast to attribute of incompatible size
+match ERROR offset 8: Cannot cast type 'uint64' to 'ipaddr'
 
 condition <ipaddr>&PMIP6-Home-IPv4-HoA == &Framed-IP-Address
 match ERROR offset 0: Cannot cast to attribute of incompatible size