]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) Fix upper bound cylinder check in check()
authorPali Rohár <pali.rohar@gmail.com>
Tue, 6 Jul 2021 16:26:52 +0000 (18:26 +0200)
committerPali Rohár <pali.rohar@gmail.com>
Thu, 15 Jul 2021 19:49:30 +0000 (21:49 +0200)
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 <pali.rohar@gmail.com>
libfdisk/src/dos.c

index f4ac1e27a839ec855775acbdaba6d5da4fd43925..5433ed84c41253428bf1f31dca8403d88e3328c8 100644 (file)
@@ -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);