From: Alan T. DeKok Date: Thu, 28 Apr 2022 14:41:31 +0000 (-0400) Subject: just call flatten_argv() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=167e580b1374b9e6554dbf525771d99e35b0af55;p=thirdparty%2Ffreeradius-server.git just call flatten_argv() 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. --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index dad289c5ff3..6cbf49721d9 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -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(); diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index 68da41a4c81..32fc8b329b7 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -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); diff --git a/src/lib/unlang/xlat_eval.c b/src/lib/unlang/xlat_eval.c index c638baaae40..fc5b9de11eb 100644 --- a/src/lib/unlang/xlat_eval.c +++ b/src/lib/unlang/xlat_eval.c @@ -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; } diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index d27f2dd2383..8d62ea5977c 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -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; diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 97976a07578..a55eafa713c 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -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: