From: Alan T. DeKok Date: Mon, 24 Mar 2025 11:04:51 +0000 (+0200) Subject: don't assume that the xlat outputs are string X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8809a03d03e95b1fe1255f4dbbd74c0ab23f4ada;p=thirdparty%2Ffreeradius-server.git don't assume that the xlat outputs are string 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 --- diff --git a/src/lib/unlang/switch.c b/src/lib/unlang/switch.c index 8f0e2593989..dda800246ad 100644 --- a/src/lib/unlang/switch.c +++ b/src/lib/unlang/switch.c @@ -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.