From: Arran Cudbard-Bell Date: Wed, 1 Dec 2021 14:31:24 +0000 (-0600) Subject: xlat_copy should actually insert the nodes it copies X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef5cb30bb4139ca6b4fbb290abb3b27ff57997a0;p=thirdparty%2Ffreeradius-server.git xlat_copy should actually insert the nodes it copies --- diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index aaca9d3adda..8793150f2c9 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -431,7 +431,7 @@ tmpl_t *xlat_to_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t *xlat); int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, tmpl_t **vpt_p); -int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *in); +int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t const *in); /* * xlat_inst.c diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 0d9ef3d4487..7e0bb053e3b 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -1892,10 +1892,10 @@ int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_t **head, xlat_flags_t *flags, * - 0 on success. * - -1 on failure. */ -int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *in) +int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t const *in) { - xlat_exp_t *p; - fr_cursor_t out_cursor, in_cursor; + xlat_exp_t const *p; + fr_cursor_t out_cursor; if (!in) { *out = NULL; @@ -1903,12 +1903,11 @@ int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *in) } fr_cursor_talloc_init(&out_cursor, out, xlat_exp_t); - fr_cursor_talloc_init(&in_cursor, &in, xlat_exp_t); /* * Copy everything in the list of nodes */ - while ((p = fr_cursor_next(&in_cursor))) { + for (p = in; p; p = p->next) { xlat_exp_t *node; MEM(node = xlat_exp_alloc(ctx, p->type, p->fmt, talloc_array_length(p->fmt) - 1)); @@ -1925,12 +1924,12 @@ int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *in) case XLAT_BOX: if (unlikely(fr_value_box_copy(node, &node->data, &p->data) < 0)) goto error; - continue; + break; case XLAT_ONE_LETTER: /* Done with format */ case XLAT_FUNC_UNRESOLVED: case XLAT_VIRTUAL_UNRESOLVED: - continue; + break; case XLAT_FUNC: case XLAT_VIRTUAL: @@ -1947,7 +1946,7 @@ int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *in) node->call.func = p->call.func; node->call.ephemeral = p->call.ephemeral; if (unlikely(xlat_copy(node, &node->child, p->child) < 0)) goto error; - continue; + break; case XLAT_ATTRIBUTE: node->attr = tmpl_copy(node, p->attr); @@ -1956,17 +1955,19 @@ int xlat_copy(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_t *in) #ifdef HAVE_REGEX case XLAT_REGEX: node->regex_index = p->regex_index; - continue; + break; #endif case XLAT_ALTERNATE: if (unlikely(xlat_copy(node, &node->alternate, p->alternate) < 0)) goto error; - continue; + break; case XLAT_GROUP: if (unlikely(xlat_copy(node, &node->child, p->child) < 0)) goto error; - continue; + break; } + + fr_cursor_insert(&out_cursor, node); } return 0;