summaryrefslogtreecommitdiff
path: root/sys/arch/sparc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-01-05 04:29:04 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-01-05 04:29:04 +0000
commita2c265cd53f9ad094038a1c234f962fd584168a1 (patch)
tree0a0c3ce35df2b2285b6c02dc49f4040ef2b12309 /sys/arch/sparc
parent245bd18b98b49158bfffe447accb65616ac74c50 (diff)
be extra careful to not divide by zero; more arches to come
Diffstat (limited to 'sys/arch/sparc')
-rw-r--r--sys/arch/sparc/sparc/disksubr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/sys/arch/sparc/sparc/disksubr.c b/sys/arch/sparc/sparc/disksubr.c
index 3de46d07cc5..1b5c134a8c0 100644
--- a/sys/arch/sparc/sparc/disksubr.c
+++ b/sys/arch/sparc/sparc/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.21 1998/10/03 21:18:56 millert Exp $ */
+/* $OpenBSD: disksubr.c,v 1.22 1999/01/05 04:29:03 millert Exp $ */
/* $NetBSD: disksubr.c,v 1.16 1996/04/28 20:25:59 thorpej Exp $ */
/*
@@ -318,6 +318,12 @@ bounds_check_with_label(bp, lp, osdep, wlabel)
goto bad;
}
+ /* avoid division by zero */
+ if (lp->d_secpercyl == 0) {
+ bp->b_error = EINVAL;
+ goto bad;
+ }
+
/* beyond partition? */
if (bp->b_blkno + sz > blockpersec(p->p_size, lp)) {
sz = blockpersec(p->p_size, lp) - bp->b_blkno;
@@ -521,7 +527,8 @@ disklabel_bsd_to_sun(lp, cp)
int i, secpercyl;
u_short cksum, *sp1, *sp2;
- if (lp->d_secsize != 512)
+ /* Enforce preconditions */
+ if (lp->d_secsize != 512 || lp->d_nsectors == 0 || lp->d_ntracks == 0)
return (EINVAL);
sl = (struct sun_disklabel *)cp;