]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
resolve strings at parse time, where they're static strings
authorAlan T. DeKok <aland@freeradius.org>
Thu, 2 Jun 2022 19:17:11 +0000 (15:17 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2022 11:16:01 +0000 (07:16 -0400)
which don't contain exec, xlat, etc.

src/lib/unlang/xlat_expr.c
src/tests/unit/xlat/cond_base.txt

index c3ea69294a6886b37ad2a0652ca86bd3ad2a301f..76e3d1e7564c2ec4394697ff3d6194716f872474 100644 (file)
@@ -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);
 
index 637f1786e74ea17296c30e2b6889e0c2f16396af..59c4914c5ab49daecb97a7ed1b857e0d3fed8bfc 100644 (file)
@@ -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 &not-a-list.User-Name == &not-a-list.User-Name
 match ERROR offset 1: Attribute 'not' not found.  Searched in: RADIUS, internal: Unresolved attributes are not allowed here