]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
better way to check for parent
authorAlan T. DeKok <aland@freeradius.org>
Thu, 17 Jun 2021 19:04:45 +0000 (15:04 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 21 Jun 2021 20:53:28 +0000 (16:53 -0400)
it's OK to have a common parent.  It's not OK for the referenced
attribute to be the exact parent of a ref

src/lib/util/dict_fixup.c

index a0cc2c7997dec35a1655e903c53bcbfecaff3ad8..777c487fa6523975b5d9fbe84131b46b4c9b2447 100644 (file)
@@ -412,8 +412,30 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu
        fr_dict_attr_t          *cloned;
        fr_dict_t               *dict = fr_dict_unconst(fr_dict_by_da(fixup->da));
 
-       da = dict_find_or_load_reference(&dict, fixup->ref, fixup->common.filename, fixup->common.line);
-       if (!da) return -1;
+       /*
+        *      We can't clone our parents.
+        */
+       da = fr_dict_attr_by_oid(NULL, fr_dict_root(dict), fixup->ref);
+       if (da) {
+               /*
+                *      The referenced DA is higher than the one we're
+                *      creating.  Ensure it's not a parent.
+                */
+               if (da->depth < fixup->da->depth) {
+                       fr_dict_attr_t const *parent;
+
+                       for (parent = fixup->da->parent; !parent->flags.is_root; parent = parent->parent) {
+                               if (parent == da) {
+                                       fr_strerror_printf("Clone references MUST NOT refer to a parent attribute %s at %s[%d]",
+                                                          parent->name, fr_cwd_strip(fixup->common.filename), fixup->common.line);
+                                       return -1;
+                               }
+                       }
+               }
+       } else {
+               da = dict_find_or_load_reference(&dict, fixup->ref, fixup->common.filename, fixup->common.line);
+               if (!da) return -1;
+       }
 
        /*
         *      We can only clone attributes of the same data type.