]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use names consitent with tmpls
authorAlan T. DeKok <aland@freeradius.org>
Mon, 17 Mar 2025 03:00:21 +0000 (10:00 +0700)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 17 Mar 2025 04:26:53 +0000 (11:26 +0700)
and purify shouldn't set the name buffer to vb_strvalue.  even
though it's been purified, it's bad process.  In theory, the
value-box can be cast to something else at some point

src/lib/unlang/xlat_alloc.c
src/lib/unlang/xlat_expr.c
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_purify.c
src/lib/unlang/xlat_tokenize.c

index 86b0af147bdcc8a89ec6f5d9a00985494940fc9b..9fa6b22d254196d79592eea89943095f43ca4dad 100644 (file)
@@ -193,7 +193,7 @@ void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len)
        fr_assert(node->fmt != fmt);
 
        if (node->fmt) talloc_const_free(node->fmt);
-       node->fmt = talloc_bstrndup(node, fmt, len);
+       MEM(node->fmt = talloc_bstrndup(node, fmt, len));
 }
 
 /** Set the format string for an xlat node, copying from a talloc'd buffer
@@ -210,7 +210,7 @@ void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt)
                        talloc_const_free(node->fmt);
                }
        }
-       node->fmt = talloc_typed_strdup_buffer(node, fmt);
+       MEM(node->fmt = talloc_typed_strdup_buffer(node, fmt));
 }
 
 /** Set the format string for an xlat node from a pre-existing buffer
@@ -218,7 +218,7 @@ void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt)
  * @param[in] node     to set fmt for.
  * @param[in] fmt      talloced buffer to set as the fmt string.
  */
-void xlat_exp_set_name_buffer_shallow(xlat_exp_t *node, char const *fmt)
+void xlat_exp_set_name_shallow(xlat_exp_t *node, char const *fmt)
 {
        fr_assert(node->fmt != fmt);
 
index 4d4382029fc482759c81b605426d481498edf839..168617c2a288d7b37661887e11a7745e5fe02f53 100644 (file)
@@ -92,7 +92,7 @@ static void xlat_func_append_arg(xlat_exp_t *head, xlat_exp_t *node, bool exists
        group = xlat_exp_alloc(head->call.args, XLAT_GROUP, NULL, 0);
        group->quote = T_BARE_WORD;
 
-       xlat_exp_set_name_buffer_shallow(group, node->fmt); /* not entirely correct, but good enough for now */
+       xlat_exp_set_name_shallow(group, node->fmt); /* not entirely correct, but good enough for now */
        group->flags = node->flags;
 
        talloc_steal(group->group, node);
@@ -124,7 +124,7 @@ static xlat_exp_t *xlat_exists_alloc(TALLOC_CTX *ctx, xlat_exp_t *child)
 
        fr_assert(child->type == XLAT_TMPL);
        fr_assert(tmpl_contains_attr(child->vpt));
-       xlat_exp_set_name_buffer_shallow(node, child->vpt->name);
+       xlat_exp_set_name_shallow(node, child->vpt->name);
 
        xlat_func_append_arg(node, child, false);
 
@@ -1033,7 +1033,7 @@ static int xlat_expr_logical_purify(xlat_exp_t *node, void *instance, request_t
                char *name;
 
                MEM(xlat_aprint(node, &name, group, NULL) >= 0);
-               xlat_exp_set_name_buffer_shallow(node, name);
+               xlat_exp_set_name_shallow(node, name);
        }
 
        node->group = group;
@@ -2328,7 +2328,7 @@ static fr_slen_t tokenize_regex_rhs(xlat_exp_head_t *head, xlat_exp_t **out, fr_
 
        node->vpt = vpt;
        node->quote = quote;
-       xlat_exp_set_name_buffer_shallow(node, vpt->name);
+       xlat_exp_set_name_shallow(node, vpt->name);
 
        node->flags.pure = !tmpl_contains_xlat(node->vpt);
        node->flags.needs_resolving = tmpl_needs_resolving(node->vpt);
@@ -2737,7 +2737,7 @@ static fr_slen_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuf
         */
        node->vpt = vpt;
        node->quote = quote;
-       xlat_exp_set_name_buffer_shallow(node, vpt->name);
+       xlat_exp_set_name_shallow(node, vpt->name);
 
        if (tmpl_is_data(node->vpt)) {
                /*
index f5bb04e308c887726ff5fcbc1ecb4c0d472fc1a9..dfd4c213f30e34647fbd6e0286fbf44d4f3c43d0 100644 (file)
@@ -280,7 +280,7 @@ xlat_exp_t  *_xlat_exp_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t ty
 #define                xlat_exp_alloc(_ctx, _type, _in, _inlen) _xlat_exp_alloc(NDEBUG_LOCATION_EXP _ctx, _type, _in, _inlen)
 
 void           xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len) CC_HINT(nonnull);
-void           xlat_exp_set_name_buffer_shallow(xlat_exp_t *node, char const *fmt) CC_HINT(nonnull);
+void           xlat_exp_set_name_shallow(xlat_exp_t *node, char const *fmt) CC_HINT(nonnull);
 void           xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt) CC_HINT(nonnull);
 
 /*
index f2e1a55074fbe5b8d2fefb24f58c21b16cc80001..e23109a30d6b68e334fac141a3244da71c206d75 100644 (file)
@@ -42,13 +42,13 @@ static void xlat_value_list_to_xlat(xlat_exp_head_t *head, fr_value_box_list_t *
 
                if (node->data.type == FR_TYPE_STRING) {
                        node->quote = T_DOUBLE_QUOTED_STRING;
-                       xlat_exp_set_name_buffer_shallow(node, node->data.vb_strvalue);
+                       xlat_exp_set_name_buffer(node, node->data.vb_strvalue); /* later changes can free strvalue */
                } else {
                        char *name;
 
                        node->quote = T_BARE_WORD;
                        MEM(fr_value_box_aprint(node, &name, box, NULL) >= 0);
-                       xlat_exp_set_name_buffer_shallow(node, name);
+                       xlat_exp_set_name_shallow(node, name);
                }
                talloc_free(box);
 
@@ -490,7 +490,7 @@ static int binary_peephole_optimize(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_
        if (box.type == FR_TYPE_BOOL) box.enumv = attr_expr_bool_enum;
 
        MEM(fr_value_box_aprint(node, &name, &box, NULL) >= 0);
-       xlat_exp_set_name_buffer_shallow(node, name);
+       xlat_exp_set_name_shallow(node, name);
        fr_value_box_copy(node, &node->data, &box);
 
        *out = node;
index 8d83e97464b755220cb57c86d4a84351b8775f94..ead3a733d3edfb22026a76e5df274316b9664b47 100644 (file)
@@ -479,7 +479,7 @@ static int xlat_resolve_virtual_attribute(xlat_exp_t *node, tmpl_t *vpt)
        if (!func) return -1;
 
        xlat_exp_set_type(node, XLAT_VIRTUAL);
-       xlat_exp_set_name_buffer_shallow(node, vpt->name);
+       xlat_exp_set_name_shallow(node, vpt->name);
 
        XLAT_DEBUG("VIRTUAL <-- %pV",
                   fr_box_strvalue_len(vpt->name, vpt->len));
@@ -575,7 +575,7 @@ static CC_HINT(nonnull(1,2,4)) ssize_t xlat_tokenize_attribute(xlat_exp_head_t *
                 *      this out in a later pass.
                 */
                xlat_exp_set_type(node, XLAT_VIRTUAL_UNRESOLVED);
-               xlat_exp_set_name_buffer_shallow(node, vpt->name);
+               xlat_exp_set_name_shallow(node, vpt->name);
                node->vpt = vpt;
                node->flags.needs_resolving = true;
        /*
@@ -583,7 +583,7 @@ static CC_HINT(nonnull(1,2,4)) ssize_t xlat_tokenize_attribute(xlat_exp_head_t *
         */
        } else {
                xlat_exp_set_type(node, XLAT_TMPL);
-               xlat_exp_set_name_buffer_shallow(node, vpt->name);
+               xlat_exp_set_name_shallow(node, vpt->name);
                node->vpt = vpt;
        }
 
@@ -676,7 +676,6 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
         */
        {
                int ret;
-               char *fmt;
                xlat_exp_t *node;
                xlat_exp_head_t *child;
                tmpl_rules_t my_rules;
@@ -704,9 +703,8 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
                        return -1;
                }
 
-               MEM(fmt = talloc_bstrndup(node, fr_sbuff_current(&s_m), fr_sbuff_behind(&s_m)));
-               xlat_exp_set_name_buffer_shallow(node, fmt);
-               tmpl_set_name_shallow(node->vpt, T_BARE_WORD, fmt, fr_sbuff_behind(&s_m));
+               xlat_exp_set_name(node, fr_sbuff_current(&s_m), fr_sbuff_behind(&s_m));
+               tmpl_set_name_shallow(node->vpt, T_BARE_WORD, node->fmt, fr_sbuff_behind(&s_m));
 
                tmpl_set_xlat(node->vpt, child);
                xlat_exp_insert_tail(head, node);
@@ -872,7 +870,7 @@ static CC_HINT(nonnull(1,2,4)) ssize_t xlat_tokenize_input(xlat_exp_head_t *head
                 */
                if (slen > 0) {
                do_value_box:
-                       xlat_exp_set_name_buffer_shallow(node, str);
+                       xlat_exp_set_name_shallow(node, str);
                        fr_value_box_strdup(node, &node->data, NULL, str, false);
                        fr_value_box_mark_safe_for(&node->data, t_rules->literals_safe_for);
                        node->flags.constant = true;
@@ -1467,7 +1465,6 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
        while (fr_sbuff_extend(&our_in)) {
                xlat_exp_t      *node = NULL;
                fr_token_t      quote;
-               char            *fmt;
                size_t          len;
 
                fr_sbuff_set(&m, &our_in);      /* Record start of argument */
@@ -1594,7 +1591,7 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
                                                            value_parse_rules_single_quoted.escapes);
                        if (slen < 0) goto error;
 
-                       xlat_exp_set_name_buffer_shallow(child, str);
+                       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, arg->safe_for);        /* Literal values are treated as implicitly safe */
                        child->flags.constant = true;
@@ -1621,8 +1618,7 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
                        goto error;
                }
 
-               fmt = talloc_bstrndup(node, fr_sbuff_current(&m), fr_sbuff_behind(&m));
-               xlat_exp_set_name_buffer_shallow(node, fmt);
+               xlat_exp_set_name(node, fr_sbuff_current(&m), fr_sbuff_behind(&m));
 
                /*
                 *      Assert that the parser has created things which are safe for the current argument.