]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
free the correct thing on decode error
authorAlan T. DeKok <aland@freeradius.org>
Tue, 5 Oct 2021 19:24:44 +0000 (15:24 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 5 Oct 2021 19:27:08 +0000 (15:27 -0400)
and use the parent ctx for allocations of raw attributes,
instead of the child ctx

src/lib/util/struct.c

index 11154be4c8033bdd80357597b3a8437cbffca0fc..62ba9b56d93257fdd20dda4ee4e133ecd729865f 100644 (file)
@@ -94,6 +94,7 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_dcursor_t *cursor,
                struct_vp = fr_pair_afrom_da(ctx, parent);
                if (!struct_vp) return -1;
 
+               fr_pair_list_init(&head); /* still used elsewhere */
                fr_dcursor_init(&child_cursor, &struct_vp->vp_group);
                child_ctx = struct_vp;
        }
@@ -286,9 +287,13 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_dcursor_t *cursor,
                        FR_PROTO_TRACE("fr_struct_from_network - failed decoding child VP");
                        talloc_free(vp);
                unknown:
-                       fr_pair_list_free(&head);
+                       if (nested) {
+                               TALLOC_FREE(struct_vp);
+                       } else {
+                               fr_pair_list_free(&head);
+                       }
 
-                       vp = fr_raw_from_network(child_ctx, parent, data, data_len);
+                       vp = fr_raw_from_network(ctx, parent, data, data_len);
                        if (!vp) return -1;
 
                        /*