]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow stealing of name buffer
authorAlan T. DeKok <aland@freeradius.org>
Sun, 9 Mar 2025 20:10:12 +0000 (16:10 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 9 Mar 2025 20:10:12 +0000 (16:10 -0400)
src/lib/unlang/xlat_alloc.c

index a9fdb3b77655cb142ee7efe0aec5e83ae3346db9..86b0af147bdcc8a89ec6f5d9a00985494940fc9b 100644 (file)
@@ -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);
 }