summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2014-07-11 15:54:53 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2014-07-11 15:54:53 +0000
commite1e97a7aafe936ad1f3926e07355776eb3517041 (patch)
tree6f5b9f92a17edcaad6a7e76d7cbab3ee98a9023e
parent4f974dbcf7306f25ed0c3d075c752e36558bf974 (diff)
Prevent division by zero on erroneous file systems.
ok pelikan@
-rw-r--r--sbin/fsck_ext2fs/setup.c5
-rw-r--r--sys/ufs/ext2fs/ext2fs_vfsops.c8
2 files changed, 11 insertions, 2 deletions
diff --git a/sbin/fsck_ext2fs/setup.c b/sbin/fsck_ext2fs/setup.c
index c99e0ce7895..b46b55f246c 100644
--- a/sbin/fsck_ext2fs/setup.c
+++ b/sbin/fsck_ext2fs/setup.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setup.c,v 1.20 2014/05/22 14:04:41 krw Exp $ */
+/* $OpenBSD: setup.c,v 1.21 2014/07/11 15:54:52 tobias Exp $ */
/* $NetBSD: setup.c,v 1.1 1997/06/11 11:22:01 bouyer Exp $ */
/*
@@ -272,6 +272,9 @@ readsb(int listerr)
if (sblock.e2fs.e2fs_log_bsize > 2) {
badsb(listerr, "BAD LOG_BSIZE"); return (0);
}
+ if (sblock.e2fs.e2fs_bpg == 0) {
+ badsb(listerr, "BAD BLOCKS PER GROUP"); return (0);
+ }
/* compute the dynamic fields of the in-memory sb */
/* compute dynamic sb infos */
diff --git a/sys/ufs/ext2fs/ext2fs_vfsops.c b/sys/ufs/ext2fs/ext2fs_vfsops.c
index 7324c8c23b8..28c60197ffa 100644
--- a/sys/ufs/ext2fs/ext2fs_vfsops.c
+++ b/sys/ufs/ext2fs/ext2fs_vfsops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ext2fs_vfsops.c,v 1.72 2014/07/11 14:30:52 pelikan Exp $ */
+/* $OpenBSD: ext2fs_vfsops.c,v 1.73 2014/07/11 15:54:52 tobias Exp $ */
/* $NetBSD: ext2fs_vfsops.c,v 1.1 1997/06/11 09:34:07 bouyer Exp $ */
/*
@@ -1080,6 +1080,12 @@ ext2fs_checksb(struct ext2fs *fs, int ronly)
#endif
return (EIO); /* XXX needs translation */
}
+ if (fs->e2fs_bpg == 0) {
+#ifdef DIAGNOSTIC
+ printf("Ext2 fs: bad blocks per group: 0\n");
+#endif
+ return (EIO);
+ }
if (fs2h32(fs->e2fs_rev) > E2FS_REV0) {
if (fs2h32(fs->e2fs_first_ino) != EXT2_FIRSTINO) {
printf("Ext2 fs: unsupported first inode position");