]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix __copy_partition()
authorKarel Zak <kzak@redhat.com>
Tue, 28 Jan 2020 11:46:39 +0000 (12:46 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 28 Jan 2020 11:46:39 +0000 (12:46 +0100)
The code called free() for pointers copied from the source partition.

Addresses: https://github.com/systemd/systemd/pull/14677
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/partition.c

index 9e87a6864682208d1ea8e2948fe25dd9bd8195f8..4af177d9b68c7a50ba18e11682d94eab19e5848f 100644 (file)
@@ -96,19 +96,30 @@ static struct fdisk_partition *__copy_partition(struct fdisk_partition *o)
        if (n->type)
                fdisk_ref_parttype(n->type);
 
+       /* note that strdup_between_structs() deallocates destination pointer,
+        * so make sure it's NULL as we call memcpy() before ... */
+       n->name = NULL;
        rc = strdup_between_structs(n, o, name);
+
+       n->uuid = NULL;
        if (!rc)
                rc = strdup_between_structs(n, o, uuid);
+       n->attrs = NULL;
        if (!rc)
                rc = strdup_between_structs(n, o, attrs);
+       n->fstype = NULL;
        if (!rc)
                rc = strdup_between_structs(n, o, fstype);
+       n->fsuuid = NULL;
        if (!rc)
                rc = strdup_between_structs(n, o, fsuuid);
+       n->fslabel = NULL;
        if (!rc)
                rc = strdup_between_structs(n, o, fslabel);
+       n->start_chs = NULL;
        if (!rc)
                rc = strdup_between_structs(n, o, start_chs);
+       n->end_chs = NULL;
        if (!rc)
                rc = strdup_between_structs(n, o, end_chs);