From: Pali Rohár Date: Tue, 6 Jul 2021 16:29:10 +0000 (+0200) Subject: libfdisk: (dos) Fix upper bound cylinder check in check_consistency() X-Git-Tag: v2.38-rc1~362^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=639f6507b6e2b2e9a28a602675ea50c689a2659a;p=thirdparty%2Futil-linux.git libfdisk: (dos) Fix upper bound cylinder check in check_consistency() 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 --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 5433ed84c4..d58f742709 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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)"),