From: Karel Zak Date: Tue, 28 Jan 2020 11:46:39 +0000 (+0100) Subject: libfdisk: fix __copy_partition() X-Git-Tag: v2.36-rc1~243 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=caa37b6e18fdcd29e57ab82fe1d54b293fccbf3b;p=thirdparty%2Futil-linux.git libfdisk: fix __copy_partition() The code called free() for pointers copied from the source partition. Addresses: https://github.com/systemd/systemd/pull/14677 Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 9e87a68646..4af177d9b6 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -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);