From: Alan T. DeKok Date: Mon, 8 Aug 2022 14:07:45 +0000 (-0400) Subject: ensure that the list && list_def are set correctly X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb143070a130a0f85818b1dbbf8450300ab36e82;p=thirdparty%2Ffreeradius-server.git ensure that the list && list_def are set correctly so that when we look at them later, they're consistent with the attribute references in the tmpl --- diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 143b4f54512..16d7c25de89 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -2197,7 +2197,41 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_request_ref_list_acopy(vpt, &vpt->rules.attr.request_def, t_rules->attr.request_def); } - if (tmpl_is_attr(vpt) && (tmpl_da(vpt)->type == tmpl_rules_cast(vpt))) vpt->rules.cast = FR_TYPE_NULL; + if (tmpl_is_attr(vpt)) { + /* + * Suppress useless casts. + */ + if (tmpl_da(vpt)->type == tmpl_rules_cast(vpt)) { + vpt->rules.cast = FR_TYPE_NULL; + } + + /* + * Ensure that the list is set correctly, so that + * the returned vpt just doesn't just match the + * input rules, it is also internally consistent. + */ + if (t_attr_rules->list_as_attr) { + tmpl_attr_t *ar; + + ar = tmpl_attr_list_head(&vpt->data.attribute.ar); + fr_assert(ar != NULL); + + if (ar->ar_da == request_attr_request) { + vpt->rules.attr.list_def = PAIR_LIST_REQUEST; + + } else if (ar->ar_da == request_attr_reply) { + vpt->rules.attr.list_def = PAIR_LIST_REPLY; + + } else if (ar->ar_da == request_attr_control) { + vpt->rules.attr.list_def = PAIR_LIST_CONTROL; + + } else if (ar->ar_da == request_attr_state) { + vpt->rules.attr.list_def = PAIR_LIST_STATE; + } + + vpt->data.attribute.list = vpt->rules.attr.list_def; + } + } if (!tmpl_substr_terminal_check(&our_name, p_rules)) { fr_strerror_const("Unexpected text after attribute reference");