From: Alan T. DeKok Date: Thu, 17 Jun 2021 19:04:45 +0000 (-0400) Subject: better way to check for parent X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=37dc73c67013f0dccd210d3fc64d29ffec9db26d;p=thirdparty%2Ffreeradius-server.git better way to check for parent it's OK to have a common parent. It's not OK for the referenced attribute to be the exact parent of a ref --- diff --git a/src/lib/util/dict_fixup.c b/src/lib/util/dict_fixup.c index a0cc2c7997d..777c487fa65 100644 --- a/src/lib/util/dict_fixup.c +++ b/src/lib/util/dict_fixup.c @@ -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.