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.