From: Pali Rohár Date: Tue, 6 Jul 2021 16:26:52 +0000 (+0200) Subject: libfdisk: (dos) Fix upper bound cylinder check in check() X-Git-Tag: v2.38-rc1~362^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0a0e567d84b5fb6cffb58c72c5d40191f30d441;p=thirdparty%2Futil-linux.git libfdisk: (dos) Fix upper bound cylinder check in check() To check if LBA sector can be represented in CHS without overflow it is required to check for cylinder value which belongs to the LBA sector. And not the total number of disk cylinders. Note that maximal representable total number of disk cylinders is 1024 and therefore the last cylinder which which can be stored in CHS tuple is 1023. Hence strict inequality is used. Signed-off-by: Pali Rohár --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index f4ac1e27a8..5433ed84c4 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -1532,7 +1532,7 @@ static int check(struct fdisk_context *cxt, size_t n, (uintmax_t) cxt->geom.cylinders); nerrors++; } - if (cxt->geom.cylinders <= 1024 && lba_sector != chs_sector) { + if (lba_sector / (cxt->geom.heads * cxt->geom.sectors) < 1024 && lba_sector != chs_sector) { fdisk_warnx(cxt, _("Partition %zu: LBA sector %u " "disagrees with C/H/S calculated sector %u"), n, lba_sector, chs_sector);