]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
update parser to cast RHS as string for structural types
authorAlan T. DeKok <aland@freeradius.org>
Sat, 11 Dec 2021 14:44:05 +0000 (09:44 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 11 Dec 2021 14:44:05 +0000 (09:44 -0500)
src/lib/unlang/compile.c

index 17741a119a609e4be52213254845ad5e869dcce6..e41aa96d9cbc1d73ed1d8d4cf1a9b9c26924360b 100644 (file)
@@ -1011,12 +1011,21 @@ int unlang_fixup_update(map_t *map, UNUSED void *ctx)
         *      Unless it's a unary operator in which case we
         *      ignore map->rhs.
         */
-       if (tmpl_is_attr(map->lhs)) {
+       if (tmpl_is_attr(map->lhs) && tmpl_is_unresolved(map->rhs)) {
+               fr_type_t type = tmpl_da(map->lhs)->type;
+
+               /*
+                *      @todo - allow passing octets to
+                *      FR_TYPE_STRUCT, which can then decode them as
+                *      data?  That would be rather powerful.
+                */
+               if (fr_type_is_structural(type)) type = FR_TYPE_STRING;
+
                /*
                 *      It's a literal string, just copy it.
                 *      Don't escape anything.
                 */
-               if (tmpl_cast_in_place(map->rhs, tmpl_da(map->lhs)->type, tmpl_da(map->lhs)) < 0) {
+               if (tmpl_cast_in_place(map->rhs, type, tmpl_da(map->lhs)) < 0) {
                        cf_log_perr(map->ci, "Cannot convert RHS value (%s) to LHS attribute type (%s)",
                                    fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_STRING, "<INVALID>"),
                                    fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, "<INVALID>"));
@@ -1130,11 +1139,20 @@ static int unlang_fixup_filter(map_t *map, UNUSED void *ctx)
         *      ignore map->rhs.
         */
        if (tmpl_is_attr(map->lhs) && tmpl_is_unresolved(map->rhs)) {
+               fr_type_t type = tmpl_da(map->lhs)->type;
+
+               /*
+                *      @todo - allow passing octets to
+                *      FR_TYPE_STRUCT, which can then decode them as
+                *      data?  That would be rather powerful.
+                */
+               if (fr_type_is_structural(type)) type = FR_TYPE_STRING;
+
                /*
                 *      It's a literal string, just copy it.
                 *      Don't escape anything.
                 */
-               if (tmpl_cast_in_place(map->rhs, tmpl_da(map->lhs)->type, tmpl_da(map->lhs)) < 0) {
+               if (tmpl_cast_in_place(map->rhs, type, tmpl_da(map->lhs)) < 0) {
                        cf_log_perr(map->ci, "Cannot convert RHS value (%s) to LHS attribute type (%s)",
                                    fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_STRING, "<INVALID>"),
                                    fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, "<INVALID>"));