]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fr_value_box_cast_in_place shouldn't trash the input box on error
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 23 Mar 2021 16:07:52 +0000 (16:07 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 23 Mar 2021 16:07:52 +0000 (16:07 +0000)
src/lib/util/value.c

index a60a29f8de31977bd50488f94d945777f0e4135e..35d763b32ab53d2f4b18150abcd05fa0f1fe928d 100644 (file)
@@ -3049,10 +3049,7 @@ int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb,
        /*
         *      Store list poiters to restore later - fr_value_box_cast clears them
         */
-       fr_dlist_t entry = {
-               .next = vb->entry.next,
-               .prev = vb->entry.prev
-       };
+       fr_dlist_t entry = vb->entry;
 
        /*
         *      Simple case, destination type and current
@@ -3071,8 +3068,16 @@ int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb,
         */
        fr_value_box_copy_shallow(NULL, &tmp, vb);
 
-       if (fr_value_box_cast(ctx, vb, dst_type, dst_enumv, &tmp) < 0) return -1;
-
+       if (fr_value_box_cast(ctx, vb, dst_type, dst_enumv, &tmp) < 0) {
+               /*
+                *      On error, make sure the original
+                *      box is left in a consistent state.
+                */
+               fr_value_box_copy_shallow(NULL, vb, &tmp);
+               vb->entry.next = entry.next;
+               vb->entry.prev = entry.prev;
+               return -1;
+       }
        fr_value_box_clear(&tmp);       /* Clear out any old buffers */
 
        /*