Skip to content

Commit d8b788c

Browse files
committed
use names consitent with tmpls
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
1 parent 384e9bb commit d8b788c

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

src/lib/unlang/xlat_alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len)
193193
fr_assert(node->fmt != fmt);
194194

195195
if (node->fmt) talloc_const_free(node->fmt);
196-
node->fmt = talloc_bstrndup(node, fmt, len);
196+
MEM(node->fmt = talloc_bstrndup(node, fmt, len));
197197
}
198198

199199
/** Set the format string for an xlat node, copying from a talloc'd buffer
@@ -210,15 +210,15 @@ void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt)
210210
talloc_const_free(node->fmt);
211211
}
212212
}
213-
node->fmt = talloc_typed_strdup_buffer(node, fmt);
213+
MEM(node->fmt = talloc_typed_strdup_buffer(node, fmt));
214214
}
215215

216216
/** Set the format string for an xlat node from a pre-existing buffer
217217
*
218218
* @param[in] node to set fmt for.
219219
* @param[in] fmt talloced buffer to set as the fmt string.
220220
*/
221-
void xlat_exp_set_name_buffer_shallow(xlat_exp_t *node, char const *fmt)
221+
void xlat_exp_set_name_shallow(xlat_exp_t *node, char const *fmt)
222222
{
223223
fr_assert(node->fmt != fmt);
224224

src/lib/unlang/xlat_expr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void xlat_func_append_arg(xlat_exp_t *head, xlat_exp_t *node, bool exists
9292
group = xlat_exp_alloc(head->call.args, XLAT_GROUP, NULL, 0);
9393
group->quote = T_BARE_WORD;
9494

95-
xlat_exp_set_name_buffer_shallow(group, node->fmt); /* not entirely correct, but good enough for now */
95+
xlat_exp_set_name_shallow(group, node->fmt); /* not entirely correct, but good enough for now */
9696
group->flags = node->flags;
9797

9898
talloc_steal(group->group, node);
@@ -124,7 +124,7 @@ static xlat_exp_t *xlat_exists_alloc(TALLOC_CTX *ctx, xlat_exp_t *child)
124124

125125
fr_assert(child->type == XLAT_TMPL);
126126
fr_assert(tmpl_contains_attr(child->vpt));
127-
xlat_exp_set_name_buffer_shallow(node, child->vpt->name);
127+
xlat_exp_set_name_shallow(node, child->vpt->name);
128128

129129
xlat_func_append_arg(node, child, false);
130130

@@ -1033,7 +1033,7 @@ static int xlat_expr_logical_purify(xlat_exp_t *node, void *instance, request_t
10331033
char *name;
10341034

10351035
MEM(xlat_aprint(node, &name, group, NULL) >= 0);
1036-
xlat_exp_set_name_buffer_shallow(node, name);
1036+
xlat_exp_set_name_shallow(node, name);
10371037
}
10381038

10391039
node->group = group;
@@ -2328,7 +2328,7 @@ static fr_slen_t tokenize_regex_rhs(xlat_exp_head_t *head, xlat_exp_t **out, fr_
23282328

23292329
node->vpt = vpt;
23302330
node->quote = quote;
2331-
xlat_exp_set_name_buffer_shallow(node, vpt->name);
2331+
xlat_exp_set_name_shallow(node, vpt->name);
23322332

23332333
node->flags.pure = !tmpl_contains_xlat(node->vpt);
23342334
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
27372737
*/
27382738
node->vpt = vpt;
27392739
node->quote = quote;
2740-
xlat_exp_set_name_buffer_shallow(node, vpt->name);
2740+
xlat_exp_set_name_shallow(node, vpt->name);
27412741

27422742
if (tmpl_is_data(node->vpt)) {
27432743
/*

src/lib/unlang/xlat_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ xlat_exp_t *_xlat_exp_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t ty
280280
#define xlat_exp_alloc(_ctx, _type, _in, _inlen) _xlat_exp_alloc(NDEBUG_LOCATION_EXP _ctx, _type, _in, _inlen)
281281

282282
void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len) CC_HINT(nonnull);
283-
void xlat_exp_set_name_buffer_shallow(xlat_exp_t *node, char const *fmt) CC_HINT(nonnull);
283+
void xlat_exp_set_name_shallow(xlat_exp_t *node, char const *fmt) CC_HINT(nonnull);
284284
void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt) CC_HINT(nonnull);
285285

286286
/*

src/lib/unlang/xlat_purify.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ static void xlat_value_list_to_xlat(xlat_exp_head_t *head, fr_value_box_list_t *
4242

4343
if (node->data.type == FR_TYPE_STRING) {
4444
node->quote = T_DOUBLE_QUOTED_STRING;
45-
xlat_exp_set_name_buffer_shallow(node, node->data.vb_strvalue);
45+
xlat_exp_set_name_buffer(node, node->data.vb_strvalue); /* later changes can free strvalue */
4646
} else {
4747
char *name;
4848

4949
node->quote = T_BARE_WORD;
5050
MEM(fr_value_box_aprint(node, &name, box, NULL) >= 0);
51-
xlat_exp_set_name_buffer_shallow(node, name);
51+
xlat_exp_set_name_shallow(node, name);
5252
}
5353
talloc_free(box);
5454

@@ -490,7 +490,7 @@ static int binary_peephole_optimize(TALLOC_CTX *ctx, xlat_exp_t **out, xlat_exp_
490490
if (box.type == FR_TYPE_BOOL) box.enumv = attr_expr_bool_enum;
491491

492492
MEM(fr_value_box_aprint(node, &name, &box, NULL) >= 0);
493-
xlat_exp_set_name_buffer_shallow(node, name);
493+
xlat_exp_set_name_shallow(node, name);
494494
fr_value_box_copy(node, &node->data, &box);
495495

496496
*out = node;

src/lib/unlang/xlat_tokenize.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int xlat_resolve_virtual_attribute(xlat_exp_t *node, tmpl_t *vpt)
479479
if (!func) return -1;
480480

481481
xlat_exp_set_type(node, XLAT_VIRTUAL);
482-
xlat_exp_set_name_buffer_shallow(node, vpt->name);
482+
xlat_exp_set_name_shallow(node, vpt->name);
483483

484484
XLAT_DEBUG("VIRTUAL <-- %pV",
485485
fr_box_strvalue_len(vpt->name, vpt->len));
@@ -575,15 +575,15 @@ static CC_HINT(nonnull(1,2,4)) ssize_t xlat_tokenize_attribute(xlat_exp_head_t *
575575
* this out in a later pass.
576576
*/
577577
xlat_exp_set_type(node, XLAT_VIRTUAL_UNRESOLVED);
578-
xlat_exp_set_name_buffer_shallow(node, vpt->name);
578+
xlat_exp_set_name_shallow(node, vpt->name);
579579
node->vpt = vpt;
580580
node->flags.needs_resolving = true;
581581
/*
582582
* Deal with normal attribute (or list)
583583
*/
584584
} else {
585585
xlat_exp_set_type(node, XLAT_TMPL);
586-
xlat_exp_set_name_buffer_shallow(node, vpt->name);
586+
xlat_exp_set_name_shallow(node, vpt->name);
587587
node->vpt = vpt;
588588
}
589589

@@ -676,7 +676,6 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
676676
*/
677677
{
678678
int ret;
679-
char *fmt;
680679
xlat_exp_t *node;
681680
xlat_exp_head_t *child;
682681
tmpl_rules_t my_rules;
@@ -704,9 +703,8 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
704703
return -1;
705704
}
706705

707-
MEM(fmt = talloc_bstrndup(node, fr_sbuff_current(&s_m), fr_sbuff_behind(&s_m)));
708-
xlat_exp_set_name_buffer_shallow(node, fmt);
709-
tmpl_set_name_shallow(node->vpt, T_BARE_WORD, fmt, fr_sbuff_behind(&s_m));
706+
xlat_exp_set_name(node, fr_sbuff_current(&s_m), fr_sbuff_behind(&s_m));
707+
tmpl_set_name_shallow(node->vpt, T_BARE_WORD, node->fmt, fr_sbuff_behind(&s_m));
710708

711709
tmpl_set_xlat(node->vpt, child);
712710
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
872870
*/
873871
if (slen > 0) {
874872
do_value_box:
875-
xlat_exp_set_name_buffer_shallow(node, str);
873+
xlat_exp_set_name_shallow(node, str);
876874
fr_value_box_strdup(node, &node->data, NULL, str, false);
877875
fr_value_box_mark_safe_for(&node->data, t_rules->literals_safe_for);
878876
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
14671465
while (fr_sbuff_extend(&our_in)) {
14681466
xlat_exp_t *node = NULL;
14691467
fr_token_t quote;
1470-
char *fmt;
14711468
size_t len;
14721469

14731470
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
15941591
value_parse_rules_single_quoted.escapes);
15951592
if (slen < 0) goto error;
15961593

1597-
xlat_exp_set_name_buffer_shallow(child, str);
1594+
xlat_exp_set_name_shallow(child, str);
15981595
fr_value_box_strdup(child, &child->data, NULL, str, false);
15991596
fr_value_box_mark_safe_for(&child->data, arg->safe_for); /* Literal values are treated as implicitly safe */
16001597
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
16211618
goto error;
16221619
}
16231620

1624-
fmt = talloc_bstrndup(node, fr_sbuff_current(&m), fr_sbuff_behind(&m));
1625-
xlat_exp_set_name_buffer_shallow(node, fmt);
1621+
xlat_exp_set_name(node, fr_sbuff_current(&m), fr_sbuff_behind(&m));
16261622

16271623
/*
16281624
* Assert that the parser has created things which are safe for the current argument.

0 commit comments

Comments
 (0)