From: Arran Cudbard-Bell Date: Fri, 29 Oct 2021 05:30:46 +0000 (-0400) Subject: Detect partial list matches X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93eaf83c1fdce5584611c6424280c2198e0ab081;p=thirdparty%2Ffreeradius-server.git Detect partial list matches Ensures reply-message doesn't get parsed as reply.-message --- diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 3ec1f6efaba..f40186c3e05 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -1829,12 +1829,13 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) { - int ret; - size_t list_len; - tmpl_t *vpt; - fr_sbuff_t our_name = FR_SBUFF(name); /* Take a local copy in case we need to back track */ - bool ref_prefix = false; - bool is_raw = false; + int ret; + size_t list_len; + tmpl_t *vpt; + fr_sbuff_t our_name = FR_SBUFF(name); /* Take a local copy in case we need to back track */ + bool ref_prefix = false; + bool is_raw = false; + fr_sbuff_marker_t m_l; if (!t_rules) t_rules = &default_attr_rules; /* Use the defaults */ @@ -1893,6 +1894,8 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, FR_SBUFF_ERROR_RETURN(&our_name); } + fr_sbuff_marker(&m_l, &our_name); + /* * Parse the list reference * @@ -1909,6 +1912,23 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, FR_SBUFF_ERROR_RETURN(&our_name); } + /* + * Check if we need to backtrack + * + * Lists can be followed by a '.', '[', or the end of the attribute reference + * + * If we don't find any of those things it wasn't an actual list match + * but one of the list identifiers matched part of an attribute reference. + * + * i.e. reply with reply-message. + */ + if ((list_len > 0) && !fr_sbuff_is_char(&our_name, '.') && + !fr_sbuff_is_char(&our_name, '[') && !tmpl_substr_terminal_check(&our_name, p_rules)) { + fr_sbuff_set(&our_name, &m_l); + list_len = 0; + vpt->data.attribute.list = t_rules->list_def; + } + /* * Parse the attribute reference *