diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/alpha/disksubr.c | 18 | ||||
-rw-r--r-- | sys/arch/sparc/sparc/disksubr.c | 11 |
2 files changed, 26 insertions, 3 deletions
diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c index 0c247eb559d..36219e12429 100644 --- a/sys/arch/alpha/alpha/disksubr.c +++ b/sys/arch/alpha/alpha/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.26 1998/11/23 03:35:56 millert Exp $ */ +/* $OpenBSD: disksubr.c,v 1.27 1999/01/05 04:29:03 millert Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -343,6 +343,15 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) int dospartoff, cyl, i, ourpart = -1; dev_t dev; + if (lp->d_secpercyl == 0) { + msg = "invalid label, d_secpercyl == 0"; + return (msg); + } + if (lp->d_secsize == 0) { + msg = "invalid label, d_secsize == 0"; + return (msg); + } + /* do dos partitions in the process of getting disklabel? */ dospartoff = 0; cyl = I386_LABELSECTOR / lp->d_secpercyl; @@ -745,6 +754,13 @@ bounds_check_with_label(bp, lp, osdep, wlabel) lp) + osdep->labelsector; int sz = howmany(bp->b_bcount, DEV_BSIZE); + /* 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; if (sz == 0) { 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; |