]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
just call flatten_argv()
authorAlan T. DeKok <aland@freeradius.org>
Thu, 28 Apr 2022 14:41:31 +0000 (10:41 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 28 Apr 2022 14:43:40 +0000 (10:43 -0400)
and update it's API to re-parent the nodes and free the input
list, so that there's no confusion about who owns what.

src/bin/unit_test_attribute.c
src/lib/unlang/xlat.h
src/lib/unlang/xlat_eval.c
src/lib/unlang/xlat_expr.c
src/lib/unlang/xlat_tokenize.c

index dad289c5ff3265be5c4f6bfca2caf6112e4263ff..6cbf49721d9f06e4f2e0826c253facf07d841c32 100644 (file)
@@ -2775,7 +2775,7 @@ static size_t command_xlat_argv(command_result_t *result, command_file_ctx_t *cc
        char            *p;
        ssize_t         slen;
        xlat_exp_head_t *head = NULL;
-       xlat_exp_head_t const **argv;
+       xlat_exp_head_t **argv;
        size_t          len;
        size_t          input_len = strlen(in);
        char            buff[1024];
@@ -2792,7 +2792,7 @@ static size_t command_xlat_argv(command_result_t *result, command_file_ctx_t *cc
                RETURN_OK_WITH_ERROR();
        }
 
-       argc = xlat_flatten_compiled_argv(cc->tmp_ctx, &argv, head);
+       argc = xlat_flatten_compiled_argv(cc->tmp_ctx, &argv, &head);
        if (argc <= 0) {
                fr_strerror_printf_push("ERROR in argument %d", (int) -argc);
                RETURN_OK_WITH_ERROR();
index 68da41a4c8158cc9cb17626a9ed7b634e5e479c7..32fc8b329b714da193fc5cb545636e86f417c4a2 100644 (file)
@@ -286,7 +286,7 @@ ssize_t             xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request,
 int            xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request,
                                         xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx);
 
-int            xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t const ***argv, xlat_exp_head_t const *head);
+int            xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t ***argv, xlat_exp_head_t **head);
 
 bool           xlat_async_required(xlat_exp_head_t const *xlat);
 
index c638baaae40eb73e8a519be16dcaeb8676f33cae..fc5b9de11ebce14933b0d4593d53010dcedd4aad 100644 (file)
@@ -1642,31 +1642,35 @@ int xlat_aeval_compiled_argv(TALLOC_CTX *ctx, char ***argv, request_t *request,
        return count;
 }
 
-/** Turn xlat_tokenize_argv() into an argv[] array
+/** Turn xlat_tokenize_argv() into an argv[] array, and nuke the input list.
  *
  *  This is mostly for async use.
  */
-int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t const ***argv, xlat_exp_head_t const *head)
+int xlat_flatten_compiled_argv(TALLOC_CTX *ctx, xlat_exp_head_t ***argv, xlat_exp_head_t **head)
 {
        int                     i;
-       xlat_exp_head_t const   **my_argv;
+       xlat_exp_head_t         **my_argv;
        size_t                  count;
 
        count = 0;
-       xlat_exp_foreach(head, node) {
+       xlat_exp_foreach(*head, node) {
                count++;
        }
 
-       MEM(my_argv = talloc_zero_array(ctx, xlat_exp_head_t const *, count + 1));
+       MEM(my_argv = talloc_zero_array(ctx, xlat_exp_head_t *, count + 1));
        *argv = my_argv;
 
        fr_assert(done_init);
 
        i = 0;
-       xlat_exp_foreach(head, node) {
-               my_argv[i++] = node->group;
+       xlat_exp_foreach(*head, node) {
+               fr_assert(node->type == XLAT_GROUP);
+               my_argv[i++] = talloc_steal(my_argv, node->group);
        }
 
+       talloc_free(*head);
+       *head = NULL;
+
        return count;
 }
 
index d27f2dd2383ee99318dd11f01900b4a9260b6a68..8d62ea5977c0331faaccbdf260548634951bf97a 100644 (file)
@@ -440,30 +440,8 @@ static fr_slen_t xlat_expr_print_logical(fr_sbuff_t *out, xlat_exp_t const *node
 static int xlat_logical_instantiate(xlat_inst_ctx_t const *xctx)
 {
        xlat_logical_inst_t     *inst = talloc_get_type_abort(xctx->inst, xlat_logical_inst_t);
-       int i;
 
-       xlat_exp_foreach(xctx->ex->call.args, arg) {
-               inst->argc++;
-       }
-
-       inst->argv = talloc_array(inst, xlat_exp_head_t *, inst->argc);
-
-       i = 0;
-       xlat_exp_foreach(xctx->ex->call.args, arg) {
-               MEM(inst->argv[i] = xlat_exp_head_alloc(inst->argv));
-               inst->argv[i++]->next = talloc_steal(inst->argv[i], arg);
-               fr_assert(arg->type == XLAT_GROUP);
-       }
-
-       /*
-        *      The arguments are in a linked list, so unlink them,
-        */
-       for (i = 0; i < inst->argc; i++) {
-               inst->argv[i]->next->next = NULL;
-       }
-
-       xctx->ex->call.args->next = NULL;
-       TALLOC_FREE(xctx->ex->call.args);
+       inst->argc = xlat_flatten_compiled_argv(inst, &inst->argv, &xctx->ex->call.args);
        inst->sense = (xctx->ex->call.func->token == T_LOR);
 
        return 0;
index 97976a07578a6ea97fe31714906eb3bd61a0677a..a55eafa713ca66ce911f34a0dc8341e2bf0a6ec0 100644 (file)
@@ -1218,6 +1218,7 @@ ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t
        switch (node->type) {
        case XLAT_TMPL:
                fr_assert(tmpl_is_list(node->vpt) || tmpl_is_attr(node->vpt));
+               fr_assert(talloc_parent(node->vpt) == node);
                slen = tmpl_attr_print(out, node->vpt, TMPL_ATTR_REF_PREFIX_NO);
                if (slen < 0) {
                error: