From a2c265cd53f9ad094038a1c234f962fd584168a1 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 5 Jan 1999 04:29:04 +0000 Subject: be extra careful to not divide by zero; more arches to come --- sys/arch/sparc/sparc/disksubr.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sys/arch/sparc') 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; -- cgit v1.2.3