]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
let's not use vpt after it's been freed
authorAlan T. DeKok <aland@freeradius.org>
Wed, 1 Feb 2023 13:34:07 +0000 (08:34 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 1 Feb 2023 13:34:07 +0000 (08:34 -0500)
and clean up some of the other code to avoid leaks on error

src/lib/unlang/xlat_expr.c

index 4ab5f739366ac644b5b06f521ddebd286f4845ac..bcffca921ea9a06a50838c547dcedae2cca003f3 100644 (file)
@@ -2361,18 +2361,7 @@ static fr_slen_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuf
                }
 
                talloc_free(vpt);
-
-       } else {
-               /*
-                *      Else we're not hoisting, set the node to the VPT
-                */
-               node->vpt = vpt;
-               node->quote = quote;
-               node->fmt = vpt->name;
-
-               node->flags.pure = tmpl_is_data(node->vpt);
-               node->flags.constant = node->flags.pure;
-               node->flags.needs_resolving = tmpl_needs_resolving(node->vpt);
+               goto done;
        }
 
        /*
@@ -2381,7 +2370,6 @@ static fr_slen_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuf
         *      to the same da.
         */
        if (tmpl_is_attr(vpt)) {
-               fr_assert(!node->flags.pure);
                if (tmpl_attr_unknown_add(vpt) < 0) {
                        fr_strerror_printf("Failed defining attribute %s", tmpl_attr_tail_da(vpt)->name);
                        fr_sbuff_set(&our_in, &opand_m);
@@ -2389,6 +2377,17 @@ static fr_slen_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuf
                }
        }
 
+       /*
+        *      Else we're not hoisting, set the node to the VPT
+        */
+       node->vpt = vpt;
+       node->quote = quote;
+       node->fmt = vpt->name;
+
+       node->flags.pure = tmpl_is_data(node->vpt);
+       node->flags.constant = node->flags.pure;
+       node->flags.needs_resolving = tmpl_needs_resolving(node->vpt);
+
        if (tmpl_is_data(vpt)) {
                /*
                 *      Print "true" and "false" instead of "yes" and "no".