From: Alan T. DeKok Date: Tue, 5 Apr 2022 13:54:13 +0000 (-0400) Subject: update fr_pair_replace() and callers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e37bc81848ac03a1eba31aafdfc202e39ea9b0f;p=thirdparty%2Ffreeradius-server.git update fr_pair_replace() and callers it was previously never called. And documented as freeing the input VP, even though it didn't. And documented as "finding" a VP, even though it didn't. Use fr_pair_replace() in pairmove() functions, instead of having them poke the dlists themselves. --- diff --git a/src/lib/server/pairmove.c b/src/lib/server/pairmove.c index ae662b7a54..bdcc7970ee 100644 --- a/src/lib/server/pairmove.c +++ b/src/lib/server/pairmove.c @@ -141,12 +141,10 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro * the one in the "from" list. */ if (from_vp->op == T_OP_SET) { - fr_pair_t *vp; RDEBUG4("::: OVERWRITING %s FROM %d TO %d", to_vp->da->name, i, j); fr_pair_remove(from, from_vp); - vp = fr_dlist_replace(&to->order.head, to_vp, from_vp); - talloc_free(vp); + fr_pair_replace(to, to_vp, from_vp); from_vp = NULL; edited[j] = true; break; @@ -222,25 +220,19 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro */ case T_OP_LE: if (rcode > 0) { - fr_pair_t *vp; RDEBUG4("::: REPLACING %s FROM %d TO %d", from_vp->da->name, i, j); - fr_pair_remove(from, from_vp); - vp = fr_dlist_replace(&to->order.head, to_vp, from_vp); - talloc_free(vp); - from_vp = NULL; - edited[j] = true; + goto replace; } break; case T_OP_GE: if (rcode < 0) { - fr_pair_t *vp; RDEBUG4("::: REPLACING %s FROM %d TO %d", from_vp->da->name, i, j); + replace: fr_pair_remove(from, from_vp); - vp = fr_dlist_replace(&to->order.head, to_vp, from_vp); - talloc_free(vp); + fr_pair_replace(to, to_vp, from_vp); from_vp = NULL; edited[j] = true; } diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 992c39cc56..ea6ee061ca 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -1085,16 +1085,12 @@ int fr_pair_insert_before(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_ad return 0; } -/** Replace first matching VP - * - * Walks over 'list', and replaces the first VP that matches 'replace'. - * If no match is found the replacement VP is appended to the list. +/** Replace a given VP * * @note Memory used by the VP being replaced will be freed. - * @note Will not work with unknown attributes. * * @param[in,out] list pair list containing #to_replace. - * @param[in] to_replace pair to release. + * @param[in] to_replace pair to replace and free * @param[in] vp New pair to insert. */ void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp) @@ -1104,6 +1100,7 @@ void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp) fr_pair_insert_after(list, to_replace, vp); fr_pair_remove(list, to_replace); + talloc_free(to_replace); } /** Alloc a new fr_pair_t (and append)