From: Alan T. DeKok Date: Fri, 8 Jan 2021 14:50:21 +0000 (-0500) Subject: have tmpl_cast_set() call fr_type_cast() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f901d4995fc61477be2838f5d87d35d5becdd3d;p=thirdparty%2Ffreeradius-server.git have tmpl_cast_set() call fr_type_cast() and update tests to match. --- diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 919052122b9..d54be2cafa9 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -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: diff --git a/src/tests/unit/condition/base.txt b/src/tests/unit/condition/base.txt index fb94d59a37f..b45c8163591 100644 --- a/src/tests/unit/condition/base.txt +++ b/src/tests/unit/condition/base.txt @@ -425,7 +425,7 @@ match &Tmp-Integer64-0 == &reply.Foo-Stuff-Bar # Casting attributes of different size # condition &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 &PMIP6-Home-IPv4-HoA == &Framed-IP-Address match ERROR offset 0: Cannot cast to attribute of incompatible size