From ed5a0f331bd825b9613445fdf2032b6af8ef7949 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Tue, 6 Jul 2021 17:12:13 +0200 Subject: [PATCH] libfdisk: (dos) Fix setting CHS values when creating new partition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It does not matter if dos compatibility flag is turned on or off. CHS values in partition entry can overflow also when dos compatibility flag is turned off. In this case maximal representable CHS values should be used. Signed-off-by: Pali Rohár --- libfdisk/src/dos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 1a2b58f99f..f4ac1e27a8 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -926,10 +926,10 @@ static void set_partition(struct fdisk_context *cxt, dos_partition_set_start(p, start - offset); dos_partition_set_size(p, stop - start + 1); - if (is_dos_compatible(cxt) && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023)) + if (start/(cxt->geom.sectors*cxt->geom.heads) > 1023) start = cxt->geom.heads*cxt->geom.sectors*1024 - 1; set_hsc(p->bh, p->bs, p->bc, start); - if (is_dos_compatible(cxt) && (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023)) + if (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023) stop = cxt->geom.heads*cxt->geom.sectors*1024 - 1; set_hsc(p->eh, p->es, p->ec, stop); partition_set_changed(cxt, i, 1); -- 2.47.2