From: Alan T. DeKok Date: Wed, 9 Apr 2025 17:34:23 +0000 (-0400) Subject: more set / check flags for xlat expressions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1550f1e89bad4cca271586e4bec2a4ee751f177;p=thirdparty%2Ffreeradius-server.git more set / check flags for xlat expressions verify that the arguments to functions are grouped correctly --- diff --git a/src/lib/unlang/xlat_alloc.c b/src/lib/unlang/xlat_alloc.c index 62b42f80a82..f0337d540bb 100644 --- a/src/lib/unlang/xlat_alloc.c +++ b/src/lib/unlang/xlat_alloc.c @@ -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; } diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index 72c0339625d..c667642dd43 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -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, ""); 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. */ diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 8bdb00d6278..ead27df4bb5 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -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); }