From 299a31e132e4295e4693f35f12aa4e19250f2603 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Mon, 20 Sep 2021 11:43:21 -0400 Subject: [PATCH] add enums, too --- src/lib/util/dict_fixup.c | 23 +++++++++++++++++------ src/tests/unit/protocols/radius/enum.txt | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/lib/util/dict_fixup.c b/src/lib/util/dict_fixup.c index b69fe896d3..eef6db26ac 100644 --- a/src/lib/util/dict_fixup.c +++ b/src/lib/util/dict_fixup.c @@ -450,15 +450,18 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu } /* - * We can only clone attributes of the same data type. - * - * @todo - for ENUMs, we have to _manually_ clone the - * values if the types are different. This means looping + * If the attributes are of different types, then we have + * to _manually_ clone the values. This means looping * over the ref da, and _casting_ the values to the new * data type. If the cast succeeds, we add the value. - * Otherwise we don't. + * Otherwise we don't + * + * We do this if the source type is a leaf node, AND the + * types are different, or the destination has no + * children. */ - if (da->type != fixup->da->type) { + if (!fr_type_is_non_leaf(fixup->da->type) && + ((da->type != fixup->da->type) || !dict_attr_children(da))) { int copied; /* @@ -502,6 +505,14 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu return 0; } + /* + * Can't clone KEY fields directly, you MUST clone the parent struct. + */ + if (!fr_type_is_non_leaf(da->type) || fr_dict_attr_is_key_field(da) || fr_dict_attr_is_key_field(fixup->da)) { + fr_strerror_printf("Invalid reference from '%s' to %s", fixup->ref, da->name); + return -1; + } + /* * Copy the source attribute, but with a * new name and a new attribute number. diff --git a/src/tests/unit/protocols/radius/enum.txt b/src/tests/unit/protocols/radius/enum.txt index 96073164d0..4aafb56b67 100644 --- a/src/tests/unit/protocols/radius/enum.txt +++ b/src/tests/unit/protocols/radius/enum.txt @@ -14,7 +14,7 @@ match fe 0c 0c 0a 00 00 00 00 00 00 00 01 # @todo - find out why this isn't an enum lookup :( # decode-pair - -match Unit-TLV = { Test-Enum-Integer64 = 1 } +match Unit-TLV = { Test-Enum-Integer64 = one } # # Same enum names, different attribute. -- 2.47.2