]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
don't assume that the xlat outputs are string
authorAlan T. DeKok <aland@freeradius.org>
Mon, 24 Mar 2025 11:04:51 +0000 (13:04 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 25 Mar 2025 12:17:47 +0000 (08:17 -0400)
they could be something else.  We never noticed before because
the rest of the code just mashed all of the switch keys to string,
too.

Now that we're a bit smarter, we can automatically determine the
data types for xlat functions.  So the key expansion for switch
statements should always cast to value_box, and not to string

src/lib/unlang/switch.c

index 8f0e2593989fd9d03f2662544bb454d5a7b67ee3..dda800246ad011dbd9e8a8b946e788587a79230e 100644 (file)
@@ -34,7 +34,6 @@ static unlang_action_t unlang_switch(rlm_rcode_t *p_result, request_t *request,
        unlang_group_t          *switch_g;
        unlang_switch_t         *switch_gext;
 
-       tmpl_t                  vpt;
        fr_value_box_t const    *box = NULL;
 
        fr_pair_t               *vp;
@@ -81,15 +80,12 @@ static unlang_action_t unlang_switch(rlm_rcode_t *p_result, request_t *request,
         */
        } else if (tmpl_is_xlat(switch_gext->vpt) ||
                   tmpl_is_exec(switch_gext->vpt)) {
-               char *p;
-               ssize_t len;
+               ssize_t slen;
 
-               len = tmpl_aexpand(request, &p, request, switch_gext->vpt, NULL, NULL);
-               if (len < 0) goto find_null_case;
+               slen = tmpl_aexpand_type(unlang_interpret_frame_talloc_ctx(request), &box, FR_TYPE_VALUE_BOX,
+                                        request, switch_gext->vpt);
+               if (slen < 0) goto find_null_case;
 
-               tmpl_init_shallow(&vpt, TMPL_TYPE_DATA, T_SINGLE_QUOTED_STRING, p, len, NULL);
-               fr_value_box_bstrndup_shallow(&vpt.data.literal, NULL, p, len, false);
-               box = tmpl_value(&vpt);
        } else if (!fr_cond_assert_msg(0, "Invalid tmpl type %s", tmpl_type_to_str(switch_gext->vpt->type))) {
                return UNLANG_ACTION_FAIL;
        }
@@ -109,8 +105,6 @@ static unlang_action_t unlang_switch(rlm_rcode_t *p_result, request_t *request,
        }
 
 do_null_case:
-       if (box == tmpl_value(&vpt)) fr_value_box_clear_value(&vpt.data.literal);
-
        /*
         *      Nothing found.  Just continue, and ignore the "switch"
         *      statement.