Skip to content

Commit af86641

Browse files
committed
add more XLAT_VERIFY, and verify XLAT_TMPL, too
1 parent 5ea2a31 commit af86641

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/lib/unlang/xlat_alloc.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,63 @@ void xlat_exp_verify(xlat_exp_t const *node)
350350
(void)talloc_get_type_abort_const(node->fmt, char);
351351
return;
352352

353+
case XLAT_TMPL: {
354+
tmpl_t const *vpt = node->vpt;
355+
356+
if (node->quote != node->vpt->quote) {
357+
if (node->vpt->quote == T_SOLIDUS_QUOTED_STRING) {
358+
/*
359+
* m'foo' versus /foo/
360+
*/
361+
fr_assert(node->quote != T_BARE_WORD);
362+
} else {
363+
/*
364+
* Mismatching quotes are bad.
365+
*/
366+
fr_assert(node->quote == T_BARE_WORD);
367+
}
368+
}
369+
370+
if (tmpl_is_attr(vpt)) {
371+
fr_dict_attr_t const *da;
372+
da = tmpl_attr_tail_da(node->vpt);
373+
374+
if (tmpl_rules_cast(node->vpt) != FR_TYPE_NULL) {
375+
/*
376+
* Casts must be omitted, unless we're using a cast as a way to get rid
377+
* of enum names.
378+
*/
379+
if (tmpl_rules_cast(node->vpt) == da->type) {
380+
fr_assert(da->flags.has_value);
381+
}
382+
383+
} else if (node->quote != T_BARE_WORD) {
384+
fr_assert(da->type != FR_TYPE_STRING);
385+
}
386+
387+
return;
388+
}
389+
390+
/*
391+
* Casts should have been hoisted.
392+
*/
393+
if (tmpl_is_data(node->vpt)) {
394+
fr_assert(tmpl_rules_cast(node->vpt) == FR_TYPE_NULL);
395+
}
396+
397+
#if 0
398+
/*
399+
* @todo - xlats SHOULD have been hoisted, unless they're quoted or cast.
400+
*/
401+
if (tmpl_is_xlat(node->vpt)) {
402+
fr_assert((node->vpt->quote != T_BARE_WORD) ||
403+
(tmpl_rules_cast(node->vpt) != FR_TYPE_NULL));
404+
return;
405+
}
406+
#endif
407+
return;
408+
}
409+
353410
default:
354411
break;
355412
}

src/lib/unlang/xlat_expr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,6 +3271,7 @@ static fr_slen_t xlat_tokenize_expression_internal(TALLOC_CTX *ctx, xlat_exp_hea
32713271
node = xlat_exists_alloc(head, node);
32723272
}
32733273

3274+
XLAT_VERIFY(node);
32743275
xlat_exp_insert_tail(head, node);
32753276

32763277
*out = head;

src/lib/unlang/xlat_tokenize.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,7 @@ int xlat_from_tmpl_attr(TALLOC_CTX *ctx, xlat_exp_head_t **out, tmpl_t **vpt_p)
20832083
fr_assert(!node->flags.pure);
20842084

20852085
done:
2086+
XLAT_VERIFY(node);
20862087
xlat_exp_insert_tail(head, node);
20872088
*out = head;
20882089

0 commit comments

Comments
 (0)