From: Arran Cudbard-Bell Date: Tue, 23 Mar 2021 16:07:52 +0000 (+0000) Subject: fr_value_box_cast_in_place shouldn't trash the input box on error X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90c1247684b2b283c6df1416c81d7facdb638f31;p=thirdparty%2Ffreeradius-server.git fr_value_box_cast_in_place shouldn't trash the input box on error --- diff --git a/src/lib/util/value.c b/src/lib/util/value.c index a60a29f8de3..35d763b32ab 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -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 */ /*