From caa37b6e18fdcd29e57ab82fe1d54b293fccbf3b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 28 Jan 2020 12:46:39 +0100 Subject: [PATCH] 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 --- libfdisk/src/partition.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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); -- 2.47.2