From: Alan T. DeKok Date: Mon, 21 Aug 2023 15:17:18 +0000 (-0400) Subject: handle key fields in unflatten X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91fd3928fb31afd2733f8b8632bd3af02d180443;p=thirdparty%2Ffreeradius-server.git handle key fields in unflatten --- diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 664ccba325f..63c46457ccb 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -3399,7 +3399,15 @@ static fr_pair_t *pair_alloc_parent(fr_pair_t *in, fr_pair_t *item, fr_dict_attr /* * We should never be called with a leaf da. + * + * If we're asked to create children of a keyed + * structure, just create the children in the parent. */ + if (!fr_type_is_structural(da->type)) { + fr_assert(fr_dict_attr_is_key_field(da)); + da = da->parent; + } + fr_assert(fr_type_is_structural(da->type)); /* @@ -3475,7 +3483,8 @@ static int pair_reparent_struct(fr_pair_t *parent, fr_pair_t *item, fr_pair_t *i for (vp = fr_pair_list_head(&in->vp_group); vp; vp = next) { next = fr_pair_list_next(&in->vp_group, vp); - fr_assert((vp->da->parent == parent->da) || (parent->vp_type == FR_TYPE_GROUP) || (parent->vp_type == FR_TYPE_VENDOR)); + fr_assert((vp->da->parent == parent->da) || (parent->vp_type == FR_TYPE_GROUP) || (parent->vp_type == FR_TYPE_VENDOR) || + (fr_dict_attr_is_key_field(vp->da->parent) && vp->da->parent->parent == parent->da)); /* * If we need a new parent, allocate it. @@ -3645,6 +3654,12 @@ int fr_pair_unflatten(fr_pair_t *in) continue; } + /* + * Sub-structures are put into their parent. + */ + if (fr_dict_attr_is_key_field(vp->da->parent) && + fr_pair_parent(vp) == in) continue; + /* * Allocate or find the parent attribute. *