From: Arran Cudbard-Bell Date: Sat, 5 Dec 2020 05:09:38 +0000 (-0700) Subject: Pass in both src and dst chunks to the copy callback X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdb1b801de5f42b8ac7046f43b9e511ec8ad03f0;p=thirdparty%2Ffreeradius-server.git Pass in both src and dst chunks to the copy callback --- diff --git a/src/lib/util/dict_ext.c b/src/lib/util/dict_ext.c index 82cd32ad79c..821a9af6070 100644 --- a/src/lib/util/dict_ext.c +++ b/src/lib/util/dict_ext.c @@ -59,11 +59,13 @@ static int fr_dict_attr_ext_name_fixup(UNUSED int ext, * */ static int fr_dict_attr_ext_enumv_copy(UNUSED int ext, - TALLOC_CTX *chunk, + TALLOC_CTX *chunk_dst, void *dst_ext_ptr, UNUSED size_t dst_ext_len, + TALLOC_CTX const *chunk_src, void *src_ext_ptr, UNUSED size_t src_ext_len) { - fr_dict_attr_t *da_src = talloc_get_type_abort(chunk, fr_dict_attr_t); + fr_dict_attr_t const *da_src = talloc_get_type_abort_const(chunk_src, fr_dict_attr_t); + fr_dict_attr_t *da_dst = talloc_get_type_abort(chunk_dst, fr_dict_attr_t); fr_dict_attr_ext_enumv_t *dst_ext = dst_ext_ptr, *src_ext = src_ext_ptr; fr_hash_iter_t iter; fr_dict_enum_t *enumv; @@ -92,7 +94,7 @@ static int fr_dict_attr_ext_enumv_copy(UNUSED int ext, /* * Fixme - Child struct copying is probably wrong */ - if (dict_attr_enum_add_name(da_src, enumv->name, enumv->value, + if (dict_attr_enum_add_name(da_dst, enumv->name, enumv->value, true, true, child_struct) < 0) return -1; } @@ -103,11 +105,12 @@ static int fr_dict_attr_ext_enumv_copy(UNUSED int ext, * */ static int fr_dict_attr_ext_vendor_copy(UNUSED int ext, - TALLOC_CTX *chunk, + TALLOC_CTX *chunk_dst, void *dst_ext_ptr, UNUSED size_t dst_ext_len, + UNUSED TALLOC_CTX const *chunk_src, void *src_ext_ptr, UNUSED size_t src_ext_len) { - fr_dict_attr_t *da_src = talloc_get_type_abort(chunk, fr_dict_attr_t); + fr_dict_attr_t *da_dst = talloc_get_type_abort_const(chunk_dst, fr_dict_attr_t); fr_dict_attr_ext_vendor_t *dst_ext = dst_ext_ptr, *src_ext = src_ext_ptr; fr_dict_attr_t const **da_stack; fr_dict_attr_t const *old_vendor = src_ext->vendor; @@ -123,7 +126,7 @@ static int fr_dict_attr_ext_vendor_copy(UNUSED int ext, * find a vendor at the same depth as * the old depth. */ - da_stack = fr_dict_attr_da_stack(da_src); + da_stack = fr_dict_attr_da_stack(da_dst); if (da_stack) { new_vendor = da_stack[old_vendor->depth]; if ((new_vendor->type == old_vendor->type) && (new_vendor->attr == old_vendor->attr)) { @@ -139,7 +142,7 @@ static int fr_dict_attr_ext_vendor_copy(UNUSED int ext, * Theoretically the attribute could * have been moved to a different depth. */ - for (da = da_src->parent; da; da = da->parent) { + for (da = da_dst->parent; da; da = da->parent) { if ((da->type == old_vendor->type) && (da->attr == old_vendor->attr)) { dst_ext->vendor = da; return 0; diff --git a/src/lib/util/ext.c b/src/lib/util/ext.c index 436e25a01ff..df4cef0e542 100644 --- a/src/lib/util/ext.c +++ b/src/lib/util/ext.c @@ -194,6 +194,7 @@ void *fr_ext_copy(fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX const info->copy(ext, *chunk_dst, ext_dst_ptr, fr_ext_len(def, *chunk_dst, ext), + chunk_src, ext_src_ptr, fr_ext_len(def, chunk_src, ext)); /* * If there's no special copy function @@ -298,6 +299,7 @@ int fr_ext_copy_all(fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX cons *chunk_dst, fr_ext_ptr(*chunk_dst, ext_dst_offsets[i], info->has_hdr), fr_ext_len(def, *chunk_dst, i), + chunk_src, fr_ext_ptr(chunk_src, ext_src_offsets[i], info->has_hdr), fr_ext_len(def, chunk_src, i)) < 0) return -1; /* diff --git a/src/lib/util/ext.h b/src/lib/util/ext.h index 1b9cc23304f..b60753910a8 100644 --- a/src/lib/util/ext.h +++ b/src/lib/util/ext.h @@ -73,17 +73,20 @@ typedef void *(* fr_ext_alloc_t)(fr_ext_t const *def, TALLOC_CTX **dst_chunk_p, /** Function for re-populating extensions after they're copied * * @param[in] ext that's being copied. - * @param[in] chunk Talloc chunk we're copying to. + * @param[in] dst_chunk Talloc chunk we're copying to. * @param[in] dst_ext_ptr Pointer to the dst extension to populate. * @param[in] dst_ext_len The length of the dst extension. + * @param[in] src_chunk Talloc chunk we're copying from. * @param[in] src_ext_ptr Pointer for the src extension. * @param[in] src_ext_len Length of the src extension. * @return * - NULL on error. * - Pointer to the new extension on success. */ -typedef int (* fr_ext_copy_t)(int ext, TALLOC_CTX *chunk, +typedef int (* fr_ext_copy_t)(int ext, + TALLOC_CTX *dst_chunk, void *dst_ext_ptr, size_t dst_ext_len, + TALLOC_CTX const *src_chunk, void *src_ext_ptr, size_t src_ext_len); /** Function for re-establishing internal consistency on realloc