]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) Fix upper bound cylinder check in check_consistency()
authorPali Rohár <pali.rohar@gmail.com>
Tue, 6 Jul 2021 16:29:10 +0000 (18:29 +0200)
committerPali Rohár <pali.rohar@gmail.com>
Thu, 15 Jul 2021 19:49:30 +0000 (21:49 +0200)
To determinate if CHS values are valid for consistency check and not
overflowed, it is needed to check current CHS cylinder value and not total
disk cylinder values. It is possible that also on "big" disk there is first
small partition which can be represented by CHS tuple.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
libfdisk/src/dos.c

index 5433ed84c41253428bf1f31dca8403d88e3328c8..d58f742709854eea74813f2140626a9f7b95764c 100644 (file)
@@ -1590,7 +1590,7 @@ static int check_consistency(struct fdisk_context *cxt, struct dos_partition *p,
        long2chs(cxt, dos_partition_get_start(p) + dos_partition_get_size(p) - 1, &lec, &leh, &les);
 
        /* Same physical / logical beginning? */
-       if (cxt->geom.cylinders <= 1024
+       if (lbc < 1024
            && (pbc != lbc || pbh != lbh || pbs != lbs)) {
                fdisk_warnx(cxt, _("Partition %zu: different physical/logical "
                        "beginnings (non-Linux?): "
@@ -1602,7 +1602,7 @@ static int check_consistency(struct fdisk_context *cxt, struct dos_partition *p,
        }
 
        /* Same physical / logical ending? */
-       if (cxt->geom.cylinders <= 1024
+       if (lec < 1024
            && (pec != lec || peh != leh || pes != les)) {
                fdisk_warnx(cxt, _("Partition %zu: different physical/logical "
                        "endings: phys=(%d, %d, %d), logical=(%d, %d, %d)"),