From 79f37ec4e1ab65664a2930793f497b288563e907 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 19 Jul 2019 13:35:11 +0200 Subject: libfdisk: Fix double free of *_chs strings in fdisk_partition __copy_partition doesn't duplicate these strings which leads to occasional double free. Signed-off-by: Vojtech Trefny --- libfdisk/src/partition.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libfdisk/src/partition.c') diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 05474a041..55ce1ca5c 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -100,6 +100,10 @@ static struct fdisk_partition *__copy_partition(struct fdisk_partition *o) n->fsuuid = strdup(o->fsuuid); if (o->fslabel) n->fslabel = strdup(o->fslabel); + if (o->start_chs) + n->start_chs = strdup(o->start_chs); + if (o->end_chs) + n->end_chs = strdup(o->end_chs); return n; } -- cgit v1.2.3-55-g7522 From 10c39f03a1e70cf2a4b8e0301784174ac5730251 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 22 Jul 2019 12:09:38 +0200 Subject: libfdisk: improve partition copy on resize It seems pretty fragile to copy also reference counting and reference to table list. Addresses: https://github.com/karelzak/util-linux/pull/822 Signed-off-by: Karel Zak --- libfdisk/src/partition.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libfdisk/src/partition.c') diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 55ce1ca5c..80a43ffde 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -85,7 +85,13 @@ static struct fdisk_partition *__copy_partition(struct fdisk_partition *o) if (!n) return NULL; + memcpy(n, o, sizeof(*n)); + + /* do not copy reference to lists, etc.*/ + n->refcount = 1; + INIT_LIST_HEAD(&n->parts); + if (n->type) fdisk_ref_parttype(n->type); if (o->name) -- cgit v1.2.3-55-g7522