From: Alan T. DeKok Date: Sun, 9 Mar 2025 20:10:12 +0000 (-0400) Subject: allow stealing of name buffer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5be9ab436705ee39640c03a2e517470d48034a5;p=thirdparty%2Ffreeradius-server.git allow stealing of name buffer --- diff --git a/src/lib/unlang/xlat_alloc.c b/src/lib/unlang/xlat_alloc.c index a9fdb3b776..86b0af147b 100644 --- a/src/lib/unlang/xlat_alloc.c +++ b/src/lib/unlang/xlat_alloc.c @@ -190,6 +190,8 @@ xlat_exp_t *_xlat_exp_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t ty */ void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len) { + fr_assert(node->fmt != fmt); + if (node->fmt) talloc_const_free(node->fmt); node->fmt = talloc_bstrndup(node, fmt, len); } @@ -201,7 +203,13 @@ void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len) */ void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt) { - if (node->fmt) talloc_const_free(node->fmt); + if (node->fmt) { + if (node->fmt == fmt) { + (void) talloc_steal(node, fmt); + } else { + talloc_const_free(node->fmt); + } + } node->fmt = talloc_typed_strdup_buffer(node, fmt); } @@ -212,6 +220,8 @@ void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt) */ void xlat_exp_set_name_buffer_shallow(xlat_exp_t *node, char const *fmt) { + fr_assert(node->fmt != fmt); + if (node->fmt) talloc_const_free(node->fmt); node->fmt = talloc_get_type_abort_const(fmt, char); }