]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
update fr_pair_replace() and callers
authorAlan T. DeKok <aland@freeradius.org>
Tue, 5 Apr 2022 13:54:13 +0000 (09:54 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 5 Apr 2022 13:54:13 +0000 (09:54 -0400)
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.

src/lib/server/pairmove.c
src/lib/util/pair.c

index ae662b7a54dda660dd9b003f5ec39fe7ad1e0376..bdcc7970eee7b240b8b1be442bbaeda6ef6ce4fc 100644 (file)
@@ -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;
                                        }
index 992c39cc567194e7512f56feaefa0fc9e4a302ca..ea6ee061ca439dc3ec5dc547ef164ca5dcbcd1bc 100644 (file)
@@ -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)