- add a sanity check to avoid possible division by zero
- adjust sector numbers _after_ "Sanity check the data against all zeroes" Should close PR bin/37656.
This commit is contained in:
parent
8c03790350
commit
aa7cb7b8f0
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fdisk.c,v 1.113 2007/12/23 10:43:57 apb Exp $ */
|
||||
/* $NetBSD: fdisk.c,v 1.114 2008/01/20 06:39:31 tsutsui Exp $ */
|
||||
|
||||
/*
|
||||
* Mach Operating System
|
||||
@ -39,7 +39,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: fdisk.c,v 1.113 2007/12/23 10:43:57 apb Exp $");
|
||||
__RCSID("$NetBSD: fdisk.c,v 1.114 2008/01/20 06:39:31 tsutsui Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#define MBRPTYPENAMES
|
||||
@ -1486,7 +1486,7 @@ intuit_translated_geometry(void)
|
||||
a2 -= s2;
|
||||
num = (uint64_t)h1 * a2 - (uint64_t)h2 * a1;
|
||||
denom = (uint64_t)c2 * a1 - (uint64_t)c1 * a2;
|
||||
if (denom != 0 && num % denom == 0) {
|
||||
if (denom != 0 && num != 0 && num % denom == 0) {
|
||||
xheads = num / denom;
|
||||
xsectors = a1 / (c1 * xheads + h1);
|
||||
break;
|
||||
@ -1551,18 +1551,20 @@ get_mapping(int i, unsigned int *cylinder, unsigned int *head, unsigned int *sec
|
||||
if (i % 2 == 0) {
|
||||
*cylinder = MBR_PCYL(part->mbrp_scyl, part->mbrp_ssect);
|
||||
*head = part->mbrp_shd;
|
||||
*sector = MBR_PSECT(part->mbrp_ssect) - 1;
|
||||
*sector = MBR_PSECT(part->mbrp_ssect);
|
||||
*absolute = le32toh(part->mbrp_start);
|
||||
} else {
|
||||
*cylinder = MBR_PCYL(part->mbrp_ecyl, part->mbrp_esect);
|
||||
*head = part->mbrp_ehd;
|
||||
*sector = MBR_PSECT(part->mbrp_esect) - 1;
|
||||
*sector = MBR_PSECT(part->mbrp_esect);
|
||||
*absolute = le32toh(part->mbrp_start)
|
||||
+ le32toh(part->mbrp_size) - 1;
|
||||
}
|
||||
/* Sanity check the data against all zeroes */
|
||||
if ((*cylinder == 0) && (*sector == 0) && (*head == 0))
|
||||
return -1;
|
||||
/* sector numbers in the MBR partition table start at 1 */
|
||||
*sector = *sector - 1;
|
||||
/* Sanity check the data against max values */
|
||||
if ((((*cylinder * MAXHEAD) + *head) * MAXSECTOR + *sector) < *absolute)
|
||||
/* cannot be a CHS mapping */
|
||||
|
Loading…
Reference in New Issue
Block a user