]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
always parse the LHS of a map as an attribute
authorAlan T. DeKok <aland@freeradius.org>
Fri, 28 Mar 2025 14:03:04 +0000 (10:03 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 28 Mar 2025 14:03:04 +0000 (10:03 -0400)
src/lib/server/map.c

index 53718e0ae3fc10e4ba13f450a08ef4ebe68e55ab..737a0a4e2fc96d4d388d5a0542a70d66ff15aa6b 100644 (file)
@@ -501,53 +501,60 @@ ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, fr_sbuf
 
                our_lhs_rules = *lhs_rules;
 
+               /*
+                *      Bare words on the LHS are always attributes.
+                *
+                *      It doesn't make sense to allow "5 = 4".  Or, "5 = NAS-Port".
+                *
+                *      The conditions do allow "5 == NAS-Port", but
+                *      they use a different parser for that.
+                */
+
+               /*
+                *      Absolute references are from the root.
+                */
+               if (!fr_sbuff_next_if_char(&our_in, '.')) {
+                       parent = NULL;
+
+               lhs_root:
+                       slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in,
+                                                     &map_parse_rules_bareword_quoted, &our_lhs_rules);
+                       break;
+               }
+
                /*
                 *      Allow for ".foo" to refer to the current
                 *      parents list.  Allow for "..foo" to refer to
                 *      the grandparent list.
                 */
-               if (our_lhs_rules.attr.prefix != TMPL_ATTR_REF_PREFIX_YES) {
-                       /*
-                        *      Absolute references are from the root.
-                        */
-                       if (!fr_sbuff_next_if_char(&our_in, '.')) {
-                               parent = NULL;
-                               goto lhs_root;
-                       }
 
-                       /*
-                        *      Relative references must have a parent.
-                        */
+               /*
+                *      Relative references must have a parent.
+                */
+               if (!parent) {
+                       fr_strerror_const("Unexpected location for relative attribute - no parent attribute exists");
+                       goto error;
+               }
+
+               /*
+                *      Multiple '.' means "go to our parents parent".
+                */
+               while (fr_sbuff_next_if_char(&our_in, '.')) {
                        if (!parent) {
-                               fr_strerror_const("Unexpected location for relative attribute - no parent attribute exists");
+                               fr_strerror_const("Too many '.' in relative reference");
                                goto error;
                        }
+                       parent = parent->parent;
+               }
 
-                       /*
-                        *      Multiple '.' means "go to our parents parent".
-                        */
-                       while (fr_sbuff_next_if_char(&our_in, '.')) {
-                               if (!parent) {
-                                       fr_strerror_const("Too many '.' in relative reference");
-                                       goto error;
-                               }
-                               parent = parent->parent;
-                       }
-
-                       if (!parent) goto lhs_root;
-
-                       /*
-                        *      Start looking in the correct parent, not in whatever we were handed.
-                        */
-                       fr_assert(tmpl_is_attr(parent->lhs));
-                       our_lhs_rules.attr.namespace = tmpl_attr_tail_da(parent->lhs);
+               if (!parent) goto lhs_root;
 
-                       slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in,
-                                                     &map_parse_rules_bareword_quoted, &our_lhs_rules);
-                       break;
-               }
+               /*
+                *      Start looking in the correct parent, not in whatever we were handed.
+                */
+               fr_assert(tmpl_is_attr(parent->lhs));
+               our_lhs_rules.attr.namespace = tmpl_attr_tail_da(parent->lhs);
 
-       lhs_root:
                slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in,
                                              &map_parse_rules_bareword_quoted, &our_lhs_rules);
                break;