summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorAaron Campbell <aaron@cvs.openbsd.org>2002-02-14 02:53:37 +0000
committerAaron Campbell <aaron@cvs.openbsd.org>2002-02-14 02:53:37 +0000
commite9c47f23dd0dd85f6f769140ca0e4e54a7d99220 (patch)
tree453dca0754edf05dcba56b07d0a953b2a6598daa /sbin
parent31ac14451b20c91d9cd20fe0c5692d0fc4b15669 (diff)
Don't divide by zero.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fsck_msdos/boot.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/sbin/fsck_msdos/boot.c b/sbin/fsck_msdos/boot.c
index ba01bc70f5f..053c405ebf5 100644
--- a/sbin/fsck_msdos/boot.c
+++ b/sbin/fsck_msdos/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.6 2001/07/03 13:03:44 ian Exp $ */
+/* $OpenBSD: boot.c,v 1.7 2002/02/14 02:53:36 aaron Exp $ */
/* $NetBSD: boot.c,v 1.5 1997/10/17 11:19:23 ws Exp $ */
/*
@@ -35,7 +35,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: boot.c,v 1.6 2001/07/03 13:03:44 ian Exp $";
+static char rcsid[] = "$OpenBSD: boot.c,v 1.7 2002/02/14 02:53:36 aaron Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -166,13 +166,8 @@ readboot(dosfs, boot)
/* Check backup FSInfo? XXX */
}
- boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
- / boot->BytesPerSec
- + boot->ResSectors
- + boot->FATs * boot->FATsecs
- - CLUST_FIRST * boot->SecPerClust;
-
- if (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) {
+ if (boot->BytesPerSec == 0 || boot->BytesPerSec % DOSBOOTBLOCKSIZE
+ != 0) {
pfatal("Invalid sector size: %u\n", boot->BytesPerSec);
return (FSFATAL);
}
@@ -180,6 +175,13 @@ readboot(dosfs, boot)
pfatal("Invalid cluster size: %u\n", boot->SecPerClust);
return (FSFATAL);
}
+
+ boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
+ / boot->BytesPerSec
+ + boot->ResSectors
+ + boot->FATs * boot->FATsecs
+ - CLUST_FIRST * boot->SecPerClust;
+
if (boot->Sectors) {
boot->HugeSectors = 0;
boot->NumSectors = boot->Sectors;