From: Alan T. DeKok Date: Thu, 2 Jun 2022 19:17:11 +0000 (-0400) Subject: resolve strings at parse time, where they're static strings X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a8041f567d336c392d6ec1f05dfb4e43e9d4184;p=thirdparty%2Ffreeradius-server.git resolve strings at parse time, where they're static strings which don't contain exec, xlat, etc. --- diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index c3ea69294a6..76e3d1e7564 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -1730,6 +1730,23 @@ static ssize_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_ node->quote = quote; node->fmt = vpt->name; + /* + * Quoted strings just get resolved now. + * + * @todo - this means that things like + * + * &Session-Timeout == '10' + * + * are run-time errors, instead of load-time parse errors. + * + * On the other hand, if people assign static strings to non-string + * attributes... they sort of deserve what they get. + */ + if ((quote != T_BARE_WORD) && tmpl_is_unresolved(node->vpt)) { + fr_assert(quote != T_BACK_QUOTED_STRING); + if (tmpl_resolve(node->vpt, NULL) < 0) return -1; + } + node->flags.pure = tmpl_is_data(node->vpt); node->flags.needs_resolving = tmpl_needs_resolving(node->vpt); diff --git a/src/tests/unit/xlat/cond_base.txt b/src/tests/unit/xlat/cond_base.txt index 637f1786e74..59c4914c5ab 100644 --- a/src/tests/unit/xlat/cond_base.txt +++ b/src/tests/unit/xlat/cond_base.txt @@ -104,22 +104,21 @@ xlat_purify ((&User-Name == &Filter-Id) || (&Reply-Message == &User-Password))) match Passed in 67 characters, but only parsed 66 characters # -# @todo - the first argument is truthy, so we should replace the -# "&&" node with just the RHS. +# Truthy strings get omitted. # xlat_purify ('handled' && (&Packet-Type == Access-Challenge)) -match ('handled' && (&Packet-Type == Access-Challenge)) +match (&Packet-Type == Access-Challenge) xlat_purify (handled && (&Packet-Type == Access-Challenge)) match (%{rcode:'handled'} && (&Packet-Type == Access-Challenge)) # This is OK, without the braces xlat_purify 'handled' && &Packet-Type == Access-Challenge -match ('handled' && (&Packet-Type == Access-Challenge)) +match (&Packet-Type == Access-Challenge) # and this, though it's not a good idea. xlat_purify 'handled' &&&Packet-Type == Access-Challenge -match ('handled' && (&Packet-Type == Access-Challenge)) +match (&Packet-Type == Access-Challenge) xlat_purify &reply == &request match ERROR offset 0: Cannot use list references in condition @@ -209,8 +208,12 @@ xlat_purify &Session-Timeout == 10 match (&Session-Timeout == 10) # Automatic type inference means this is fine + +# +# @todo - in binary resolve, cast the RHS to the type of the LHS. +# xlat_purify &Session-Timeout == '10' -match (&Session-Timeout == 10) +match (&Session-Timeout == '10') # Except for dates, which can be humanly readable! # This one is be an expansion, so it's left as-is. @@ -543,7 +546,7 @@ match ERROR offset 11: Invalid array index '-1' (should be between 0-1000) # The attribute/xlat_purify parser does not fall back to bare words # xlat_purify request.Foo == 'request.Foo' -match ERROR offset 0: Invalid attribute reference, missing '&' prefix: Failed resolving attribute in expansion: request.Foo +match ERROR offset 0: Failed resolving attribute in expansion: request.Foo xlat_purify ¬-a-list.User-Name == ¬-a-list.User-Name match ERROR offset 1: Attribute 'not' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here