Skip to content

Commit b953cac

Browse files
committed
update the tmpl_rules for argument parsing
so that we don't do casts, etc. of the function arguments
1 parent 049723b commit b953cac

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

src/lib/unlang/xlat_tokenize.c

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,8 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
13421342
fr_sbuff_parse_rules_t tmp_p_rules;
13431343
xlat_exp_head_t *head;
13441344
xlat_arg_parser_t const *arg = NULL, *arg_start;
1345+
tmpl_rules_t const *our_t_rules = t_rules;
1346+
tmpl_rules_t tmp_t_rules;
13451347

13461348
if (xlat && xlat->args) {
13471349
arg_start = arg = xlat->args; /* Track the arguments as we parse */
@@ -1371,6 +1373,28 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
13711373
fr_assert(p_rules->terminals);
13721374

13731375
our_p_rules = p_rules;
1376+
1377+
/*
1378+
* The arguments to a function are NOT the output data type of the function.
1379+
*
1380+
* We do NOT check for quotation characters. We DO update t_rules to strip any casts. The
1381+
* OUTPUT of the function is cast to the relevant data type, but each ARGUMENT is just an
1382+
* expression with no given data type. Parsing the expression is NOT done with the cast of
1383+
* arg->type, as that means each individual piece of the expression is parsed as the type. We
1384+
* have to cast on the final _output_ of the expression, and we allow the _input_ pieces of the
1385+
* expression to be just about anything.
1386+
*/
1387+
if (!xlat_func_bare_words) {
1388+
tmp_t_rules = *t_rules;
1389+
our_t_rules = &tmp_t_rules;
1390+
1391+
tmp_t_rules.enumv = NULL;
1392+
tmp_t_rules.cast = FR_TYPE_NULL;
1393+
tmp_t_rules.attr.namespace = NULL;
1394+
tmp_t_rules.attr.request_def = NULL;
1395+
tmp_t_rules.attr.list_def = request_attr_request;
1396+
tmp_t_rules.attr.list_presence = TMPL_ATTR_LIST_ALLOW;
1397+
}
13741398
}
13751399

13761400
MEM(head = xlat_exp_head_alloc(ctx));
@@ -1395,13 +1419,19 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
13951419
*/
13961420
if (!spaces) fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, NULL);
13971421

1398-
fr_sbuff_out_by_longest_prefix(&slen, &quote, xlat_quote_table, &our_in, T_BARE_WORD);
1399-
14001422
/*
14011423
* Alloc a new node to hold the child nodes
14021424
* that make up the argument.
14031425
*/
14041426
MEM(node = xlat_exp_alloc(head, XLAT_GROUP, NULL, 0));
1427+
1428+
if (!spaces && !xlat_func_bare_words) {
1429+
quote = T_BARE_WORD;
1430+
node->quote = quote;
1431+
goto tokenize_expression;
1432+
}
1433+
1434+
fr_sbuff_out_by_longest_prefix(&slen, &quote, xlat_quote_table, &our_in, T_BARE_WORD);
14051435
node->quote = quote;
14061436

14071437
switch (quote) {
@@ -1433,14 +1463,17 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
14331463
*/
14341464
slen = xlat_tokenize_input(node->group, &our_in, our_p_rules, t_rules, arg->safe_for);
14351465

1436-
} else if (fr_sbuff_is_char(&our_in, ')')) {
1437-
/*
1438-
* %foo()
1439-
*/
1440-
slen = 0;
1441-
14421466
} else {
1443-
slen = xlat_tokenize_expression(node, &node->group, &our_in, our_p_rules, t_rules);
1467+
tokenize_expression:
1468+
if (fr_sbuff_is_char(&our_in, ')')) {
1469+
/*
1470+
* %foo()
1471+
*/
1472+
slen = 0;
1473+
1474+
} else {
1475+
slen = xlat_tokenize_expression(node, &node->group, &our_in, our_p_rules, our_t_rules);
1476+
}
14441477
}
14451478
if (slen < 0) {
14461479
error:

0 commit comments

Comments
 (0)