summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1997-04-19 14:14:17 +0000
committerbde <bde@FreeBSD.org>1997-04-19 14:14:17 +0000
commitf2fed2ec029e905e21f6c7b137455d697d6bae7e (patch)
tree65ac7bf408315492f227c5b7a1f43f1acdab6e2e
parent2b13c9e07634e114240a005f28dee0707cb3648d (diff)
downloadFreeBSD-src-f2fed2ec029e905e21f6c7b137455d697d6bae7e.zip
FreeBSD-src-f2fed2ec029e905e21f6c7b137455d697d6bae7e.tar.gz
Avoid division by 0 in check_part(). (It occurred when max_nsectors == 0.
This case is clearly an error, but we keep calling check_part() to get diagnostics.) Fixed nearby indentation and commenting bugs.
-rw-r--r--sys/i386/isa/diskslice_machdep.c19
-rw-r--r--sys/kern/subr_diskmbr.c19
2 files changed, 22 insertions, 16 deletions
diff --git a/sys/i386/isa/diskslice_machdep.c b/sys/i386/isa/diskslice_machdep.c
index 8983e950c..040fc18 100644
--- a/sys/i386/isa/diskslice_machdep.c
+++ b/sys/i386/isa/diskslice_machdep.c
@@ -35,7 +35,7 @@
*
* from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91
* from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $
- * $Id$
+ * $Id: diskslice_machdep.c,v 1.24 1997/02/22 09:36:06 peter Exp $
*/
#include <stddef.h>
@@ -100,14 +100,16 @@ check_part(sname, dp, offset, nsectors, ntracks, mbr_offset )
/*
* If ssector1 is on a cylinder >= 1024, then ssector can't be right.
* Allow the C/H/S for it to be 1023/ntracks-1/nsectors, or correct
- * apart from the cylinder being reduced modulo 1024.
+ * apart from the cylinder being reduced modulo 1024. Always allow
+ * 1023/255/63.
*/
if (ssector < ssector1
&& ((chs_ssect == nsectors && dp->dp_shd == ntracks - 1
&& chs_scyl == 1023)
- || (ssector1 - ssector) % (1024 * secpercyl) == 0)
- || (dp->dp_scyl == 255 && dp->dp_shd == 255
- && dp->dp_ssect == 255)) {
+ || (secpercyl != 0
+ && (ssector1 - ssector) % (1024 * secpercyl) == 0))
+ || (dp->dp_scyl == 255 && dp->dp_shd == 255
+ && dp->dp_ssect == 255)) {
TRACE(("%s: C/H/S start %d/%d/%d, start %lu: allow\n",
sname, chs_scyl, dp->dp_shd, chs_ssect, ssector1));
ssector = ssector1;
@@ -123,9 +125,10 @@ check_part(sname, dp, offset, nsectors, ntracks, mbr_offset )
if (esector < esector1
&& ((chs_esect == nsectors && dp->dp_ehd == ntracks - 1
&& chs_ecyl == 1023)
- || (esector1 - esector) % (1024 * secpercyl) == 0)
- || (dp->dp_ecyl == 255 && dp->dp_ehd == 255
- && dp->dp_esect == 255)) {
+ || (secpercyl != 0
+ && (esector1 - esector) % (1024 * secpercyl) == 0))
+ || (dp->dp_ecyl == 255 && dp->dp_ehd == 255
+ && dp->dp_esect == 255)) {
TRACE(("%s: C/H/S end %d/%d/%d, end %lu: allow\n",
sname, chs_ecyl, dp->dp_ehd, chs_esect, esector1));
esector = esector1;
diff --git a/sys/kern/subr_diskmbr.c b/sys/kern/subr_diskmbr.c
index 8983e950c..040fc18 100644
--- a/sys/kern/subr_diskmbr.c
+++ b/sys/kern/subr_diskmbr.c
@@ -35,7 +35,7 @@
*
* from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91
* from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $
- * $Id$
+ * $Id: diskslice_machdep.c,v 1.24 1997/02/22 09:36:06 peter Exp $
*/
#include <stddef.h>
@@ -100,14 +100,16 @@ check_part(sname, dp, offset, nsectors, ntracks, mbr_offset )
/*
* If ssector1 is on a cylinder >= 1024, then ssector can't be right.
* Allow the C/H/S for it to be 1023/ntracks-1/nsectors, or correct
- * apart from the cylinder being reduced modulo 1024.
+ * apart from the cylinder being reduced modulo 1024. Always allow
+ * 1023/255/63.
*/
if (ssector < ssector1
&& ((chs_ssect == nsectors && dp->dp_shd == ntracks - 1
&& chs_scyl == 1023)
- || (ssector1 - ssector) % (1024 * secpercyl) == 0)
- || (dp->dp_scyl == 255 && dp->dp_shd == 255
- && dp->dp_ssect == 255)) {
+ || (secpercyl != 0
+ && (ssector1 - ssector) % (1024 * secpercyl) == 0))
+ || (dp->dp_scyl == 255 && dp->dp_shd == 255
+ && dp->dp_ssect == 255)) {
TRACE(("%s: C/H/S start %d/%d/%d, start %lu: allow\n",
sname, chs_scyl, dp->dp_shd, chs_ssect, ssector1));
ssector = ssector1;
@@ -123,9 +125,10 @@ check_part(sname, dp, offset, nsectors, ntracks, mbr_offset )
if (esector < esector1
&& ((chs_esect == nsectors && dp->dp_ehd == ntracks - 1
&& chs_ecyl == 1023)
- || (esector1 - esector) % (1024 * secpercyl) == 0)
- || (dp->dp_ecyl == 255 && dp->dp_ehd == 255
- && dp->dp_esect == 255)) {
+ || (secpercyl != 0
+ && (esector1 - esector) % (1024 * secpercyl) == 0))
+ || (dp->dp_ecyl == 255 && dp->dp_ehd == 255
+ && dp->dp_esect == 255)) {
TRACE(("%s: C/H/S end %d/%d/%d, end %lu: allow\n",
sname, chs_ecyl, dp->dp_ehd, chs_esect, esector1));
esector = esector1;
OpenPOWER on IntegriCloud