]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
xlat_copy should actually insert the nodes it copies
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 1 Dec 2021 14:31:24 +0000 (08:31 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 1 Dec 2021 20:06:38 +0000 (14:06 -0600)
src/lib/unlang/xlat.h
src/lib/unlang/xlat_tokenize.c

index aaca9d3addaa1d4b49efa33d986aa2c26fa975cb..8793150f2c98aa8b9558aef10f74dc4b6626a19f 100644 (file)
@@ -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
index 0d9ef3d448731294c66acfd4c2fb5c578b2cc62b..7e0bb053e3be4353092e28ef219223b24677ffd5 100644 (file)
@@ -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;