]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Detect partial list matches
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 29 Oct 2021 05:30:46 +0000 (01:30 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 29 Oct 2021 05:30:46 +0000 (01:30 -0400)
Ensures reply-message doesn't get parsed as reply.-message

src/lib/server/tmpl_tokenize.c

index 3ec1f6efaba53ac5742bd9d0543182c7af4ef560..f40186c3e0510fc28e7fdbf2e4043cb66ef3e761 100644 (file)
@@ -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
         *