From: Arran Cudbard-Bell Date: Mon, 21 Aug 2023 22:58:16 +0000 (-0600) Subject: xlat: Fix xlat alternations that use functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d57abe4facf8ced90bb66bfab6690d5f42f0425a;p=thirdparty%2Ffreeradius-server.git xlat: Fix xlat alternations that use functions --- diff --git a/src/lib/unlang/xlat_alloc.c b/src/lib/unlang/xlat_alloc.c index 03b05f218b7..29dfbd67863 100644 --- a/src/lib/unlang/xlat_alloc.c +++ b/src/lib/unlang/xlat_alloc.c @@ -258,8 +258,15 @@ static int _xlat_copy_internal(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_exp_he * Ensure the format string is valid... At this point * they should all be talloc'd strings. */ - MEM(node = xlat_exp_alloc(ctx, p->type, - talloc_get_type_abort_const(p->fmt, char), talloc_array_length(p->fmt) - 1)); + if (p->type == XLAT_ALTERNATE) { + /* Alternates don't have format strings */ + MEM(node = xlat_exp_alloc_null(ctx)); + xlat_exp_set_type(node, XLAT_ALTERNATE); + } else { + MEM(node = xlat_exp_alloc(ctx, p->type, + talloc_get_type_abort_const(p->fmt, char), talloc_array_length(p->fmt) - 1)); + } + node->quote = p->quote; node->flags = p->flags; diff --git a/src/tests/keywords/xlat-alternation-with-func b/src/tests/keywords/xlat-alternation-with-func new file mode 100644 index 00000000000..4a5506cad7d --- /dev/null +++ b/src/tests/keywords/xlat-alternation-with-func @@ -0,0 +1,32 @@ +# +# PRE: +# + +&Tmp-String-0 := "foo" +&Tmp-String-1 := "bar" + +if (!(%{%(test.passthrough:%{Tmp-String-0}):-%{Tmp-String-1}} == 'foo')) { + test_fail +} + +if (!(%{%(test.passthrough:%{Tmp-String-2}):-%{Tmp-String-1}} == 'bar')) { + test_fail +} + +if (!(%{%{Tmp-String-0}:-%(test.passthrough:%{Tmp-String-1})} == 'foo')) { + test_fail +} + +if (!(%{%{Tmp-String-2}:-%(test.passthrough:%{Tmp-String-1})} == 'bar')) { + test_fail +} + +if (!(%{%(test.passthrough:%{Tmp-String-0}):-%(test.passthrough:%{Tmp-String-1})} == 'foo')) { + test_fail +} + +if (!(%{%(test.passthrough:%{Tmp-String-2}):-%(test.passthrough:%{Tmp-String-1})} == 'bar')) { + test_fail +} + +success