]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
more set / check flags for xlat expressions
authorAlan T. DeKok <aland@freeradius.org>
Wed, 9 Apr 2025 17:34:23 +0000 (13:34 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 9 Apr 2025 20:19:20 +0000 (16:19 -0400)
verify that the arguments to functions are grouped correctly

src/lib/unlang/xlat_alloc.c
src/lib/unlang/xlat_expr.c
src/lib/unlang/xlat_tokenize.c

index 62b42f80a8259b67c916d02b544d9bd734b3c0a9..f0337d540bb0f2d12e4857199a9a21aefd9ddc38 100644 (file)
@@ -94,6 +94,10 @@ void _xlat_exp_set_type(NDEBUG_LOCATION_ARGS xlat_exp_t *node, xlat_type_t type)
                node->call.args = _xlat_exp_head_alloc(NDEBUG_LOCATION_VALS node);
                break;
 
+       case XLAT_BOX:
+               node->flags.constant = node->flags.pure = node->flags.can_purify = true;
+               break;
+
        default:
                break;
        }
@@ -167,6 +171,10 @@ xlat_exp_t *_xlat_exp_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t ty
                                   inlen + extra);
        _xlat_exp_set_type(NDEBUG_LOCATION_VALS node, type);
 
+       if (type == XLAT_BOX) {
+               node->flags.constant = node->flags.pure = node->flags.can_purify = true;
+       }
+
        if (!in) return node;
 
        node->fmt = talloc_bstrndup(node, in, inlen);
@@ -339,6 +347,16 @@ void xlat_exp_verify(xlat_exp_t const *node)
                return;
 
        case XLAT_FUNC:
+               xlat_exp_foreach(node->call.args, arg) {
+                       fr_assert(arg->type == XLAT_GROUP);
+
+                       /*
+                        *      We can't do this yet, because the old function argument parser doesn't do the
+                        *      right thing.
+                        */
+//                     fr_assert(arg->quote == T_BARE_WORD);
+               }
+
                xlat_exp_head_verify(node->call.args);
                (void)talloc_get_type_abort_const(node->fmt, char);
                return;
@@ -400,6 +418,12 @@ void xlat_exp_verify(xlat_exp_t const *node)
                return;
        }
 
+       case XLAT_BOX:
+               fr_assert(node->flags.constant);
+               fr_assert(node->flags.pure);
+//             fr_assert(node->flags.can_purify);
+               break;
+
        default:
                break;
        }
index 72c0339625da403c8b5a33b37dfbb3f7acec5569..c667642dd43e65f45c8b1a40a1a507d6e9b29a4e 100644 (file)
@@ -2095,7 +2095,6 @@ static xlat_exp_t *expr_cast_alloc(TALLOC_CTX *ctx, fr_type_t type, xlat_exp_t *
         *      number.
         */
        MEM(node = xlat_exp_alloc(cast, XLAT_BOX, NULL, 0));
-       node->flags.constant = true;
        {
                char const *type_name = fr_table_str_by_value(fr_type_table, type, "<INVALID>");
                xlat_exp_set_name(node, type_name, strlen(type_name));
@@ -2280,11 +2279,6 @@ static ssize_t tokenize_rcode(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_
 
        MEM(arg = xlat_exp_alloc(node, XLAT_BOX, fr_sbuff_start(&our_in), slen));
 
-       /*
-        *      Doesn't need resolving, isn't pure, doesn't need anything else.
-        */
-       arg->flags = (xlat_flags_t) { };
-
        /*
         *      We need a string for unit tests, but this should really be just a number.
         */
index 8bdb00d62787234679caa8ffddd3c016a82fa98f..ead27df4bb502299e4c2a3aeddab7a97822b74b3 100644 (file)
@@ -1419,7 +1419,6 @@ static ssize_t xlat_tokenize_word(TALLOC_CTX *ctx, xlat_exp_t **out, fr_sbuff_t
                xlat_exp_set_name_shallow(child, str);
                fr_value_box_strdup(child, &child->data, NULL, str, false);
                fr_value_box_mark_safe_for(&child->data, t_rules->literals_safe_for);   /* Literal values are treated as implicitly safe */
-               child->flags.constant = true;
                fr_assert(child->flags.pure);
                xlat_exp_insert_tail(node->group, child);
        }