diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2007-06-07 00:28:18 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2007-06-07 00:28:18 +0000 |
commit | 2b983a94dd05ba0dcd4e7d0f929d8c333e8c4ff8 (patch) | |
tree | 487d5866d3971c6c771894919fbed7e18df24ad8 /sys | |
parent | 7e0751214480a4f7fe318bedcb4bf8e309a3148d (diff) |
More bounds_check_with_label homogenization. Fix a couple of typos while
there.
'so go to it!' deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/alpha/disksubr.c | 5 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/disksubr.c | 7 | ||||
-rw-r--r-- | sys/arch/arm/arm/disksubr.c | 7 | ||||
-rw-r--r-- | sys/arch/aviion/aviion/disksubr.c | 9 | ||||
-rw-r--r-- | sys/arch/hp300/hp300/disksubr.c | 7 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/disksubr.c | 5 | ||||
-rw-r--r-- | sys/arch/hppa64/hppa64/disksubr.c | 5 | ||||
-rw-r--r-- | sys/arch/i386/i386/disksubr.c | 7 | ||||
-rw-r--r-- | sys/arch/landisk/landisk/disksubr.c | 7 | ||||
-rw-r--r-- | sys/arch/luna88k/luna88k/disksubr.c | 11 | ||||
-rw-r--r-- | sys/arch/mac68k/mac68k/disksubr.c | 9 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/disksubr.c | 7 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/disksubr.c | 5 | ||||
-rw-r--r-- | sys/arch/mvme68k/mvme68k/disksubr.c | 10 | ||||
-rw-r--r-- | sys/arch/mvme88k/mvme88k/disksubr.c | 10 | ||||
-rw-r--r-- | sys/arch/mvmeppc/mvmeppc/disksubr.c | 7 | ||||
-rw-r--r-- | sys/arch/sparc/sparc/disksubr.c | 12 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/disksubr.c | 12 | ||||
-rw-r--r-- | sys/arch/vax/vax/disksubr.c | 7 |
19 files changed, 65 insertions, 84 deletions
diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c index e41fb68b0b3..695028a8191 100644 --- a/sys/arch/alpha/alpha/disksubr.c +++ b/sys/arch/alpha/alpha/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.75 2007/06/06 17:15:11 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.76 2007/06/07 00:28:16 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -538,7 +538,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -564,6 +564,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/amd64/amd64/disksubr.c b/sys/arch/amd64/amd64/disksubr.c index 63b91cd1244..9a2eb06fc35 100644 --- a/sys/arch/amd64/amd64/disksubr.c +++ b/sys/arch/amd64/amd64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.39 2007/06/06 17:15:11 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.40 2007/06/07 00:28:16 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -487,7 +487,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -500,9 +500,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; @@ -515,6 +513,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/arm/arm/disksubr.c b/sys/arch/arm/arm/disksubr.c index 99d54ca7060..c7100d48210 100644 --- a/sys/arch/arm/arm/disksubr.c +++ b/sys/arch/arm/arm/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.34 2007/06/06 17:15:11 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.35 2007/06/07 00:28:16 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -459,7 +459,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -472,9 +472,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; @@ -487,6 +485,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/aviion/aviion/disksubr.c b/sys/arch/aviion/aviion/disksubr.c index 88fb632e334..4fe5c259174 100644 --- a/sys/arch/aviion/aviion/disksubr.c +++ b/sys/arch/aviion/aviion/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.25 2007/06/06 17:15:11 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.26 2007/06/07 00:28:16 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -442,7 +442,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); - int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART], lp) + + int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART]), lp) + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); @@ -458,7 +458,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -471,9 +471,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; @@ -486,6 +484,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/hp300/hp300/disksubr.c b/sys/arch/hp300/hp300/disksubr.c index b9eb0e4cd4a..54d42d9a91d 100644 --- a/sys/arch/hp300/hp300/disksubr.c +++ b/sys/arch/hp300/hp300/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.32 2007/06/06 16:42:06 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.33 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.9 1997/04/01 03:12:13 scottr Exp $ */ /* @@ -225,7 +225,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); - int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[0]), lp) + + int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART]), lp) + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); @@ -241,7 +241,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - return (0); + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -254,6 +254,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && + bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c index ef1b35c1c32..e7e99200561 100644 --- a/sys/arch/hppa/hppa/disksubr.c +++ b/sys/arch/hppa/hppa/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.55 2007/06/06 17:15:11 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.56 2007/06/07 00:28:17 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -687,7 +687,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -713,6 +713,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/hppa64/hppa64/disksubr.c b/sys/arch/hppa64/hppa64/disksubr.c index 6fd42238d63..d99940532b2 100644 --- a/sys/arch/hppa64/hppa64/disksubr.c +++ b/sys/arch/hppa64/hppa64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.38 2007/06/06 17:15:12 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.39 2007/06/07 00:28:17 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -687,7 +687,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -713,6 +713,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c index 206453d5da6..8bad5b3019a 100644 --- a/sys/arch/i386/i386/disksubr.c +++ b/sys/arch/i386/i386/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.79 2007/06/06 17:15:12 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.80 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -487,7 +487,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -500,9 +500,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; @@ -515,6 +513,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/landisk/landisk/disksubr.c b/sys/arch/landisk/landisk/disksubr.c index 4306b2d09b0..24452100b33 100644 --- a/sys/arch/landisk/landisk/disksubr.c +++ b/sys/arch/landisk/landisk/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.22 2007/06/06 17:15:12 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.23 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -459,7 +459,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -472,9 +472,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; @@ -487,6 +485,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/luna88k/luna88k/disksubr.c b/sys/arch/luna88k/luna88k/disksubr.c index 0558c80e0f2..f0a06e6a103 100644 --- a/sys/arch/luna88k/luna88k/disksubr.c +++ b/sys/arch/luna88k/luna88k/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.18 2007/06/06 22:14:29 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.19 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.12 2002/02/19 17:09:44 wiz Exp $ */ /* @@ -302,6 +302,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); + int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART]), lp) + + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); /* avoid division by zero */ @@ -316,7 +318,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - return (0); + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -330,8 +332,9 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* overwriting disk label ? */ /* XXX this assumes everything <=LABELSECTOR is label! */ /* But since LABELSECTOR is 0, that's ok for now. */ - if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= LABELSECTOR && - (bp->b_flags & B_READ) == 0 && wlabel == 0) { + if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && + bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && + (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } diff --git a/sys/arch/mac68k/mac68k/disksubr.c b/sys/arch/mac68k/mac68k/disksubr.c index 976e0cd8d94..843144d0efc 100644 --- a/sys/arch/mac68k/mac68k/disksubr.c +++ b/sys/arch/mac68k/mac68k/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.39 2007/06/06 16:42:06 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.40 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.22 1997/11/26 04:18:20 briggs Exp $ */ /* @@ -562,7 +562,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -576,10 +576,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* overwriting disk label ? */ /* XXX should also protect bootstrap in first 8K */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif /* LABELSECTOR != 0 */ - (bp->b_flags & B_READ) == 0 && wlabel == 0) { + (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } @@ -591,6 +589,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index fccd1135086..612c595010d 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.44 2007/06/06 17:15:12 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.45 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -571,7 +571,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -584,9 +584,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; @@ -599,6 +597,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/mips64/mips64/disksubr.c b/sys/arch/mips64/mips64/disksubr.c index 80cd0166b5a..dc3db50d47c 100644 --- a/sys/arch/mips64/mips64/disksubr.c +++ b/sys/arch/mips64/mips64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.44 2007/06/06 17:15:12 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.45 2007/06/07 00:28:17 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -646,7 +646,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -672,6 +672,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/mvme68k/mvme68k/disksubr.c b/sys/arch/mvme68k/mvme68k/disksubr.c index 2f11d83e071..50ff5a51299 100644 --- a/sys/arch/mvme68k/mvme68k/disksubr.c +++ b/sys/arch/mvme68k/mvme68k/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.45 2007/06/06 16:42:06 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.46 2007/06/07 00:28:17 krw Exp $ */ /* * Copyright (c) 1998 Steve Murphree, Jr. * Copyright (c) 1995 Dale Rahn. @@ -248,7 +248,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); - int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[0]), lp) + + int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART]), lp) + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); @@ -264,7 +264,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - return(0); + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -278,10 +278,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* overwriting disk label ? */ /* XXX should also protect bootstrap in first 8K */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif - (bp->b_flags & B_READ) == 0 && wlabel == 0) { + (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } diff --git a/sys/arch/mvme88k/mvme88k/disksubr.c b/sys/arch/mvme88k/mvme88k/disksubr.c index 9a2a258aa4c..5bc3d7021c7 100644 --- a/sys/arch/mvme88k/mvme88k/disksubr.c +++ b/sys/arch/mvme88k/mvme88k/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.41 2007/06/06 16:42:06 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.42 2007/06/07 00:28:17 krw Exp $ */ /* * Copyright (c) 1998 Steve Murphree, Jr. * Copyright (c) 1995 Dale Rahn. @@ -248,7 +248,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); - int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[0]), lp) + + int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART]), lp) + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); @@ -264,7 +264,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - return(0); + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -278,10 +278,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* overwriting disk label ? */ /* XXX should also protect bootstrap in first 8K */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif - (bp->b_flags & B_READ) == 0 && wlabel == 0) { + (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } diff --git a/sys/arch/mvmeppc/mvmeppc/disksubr.c b/sys/arch/mvmeppc/mvmeppc/disksubr.c index 9b8f5736100..b583c25cb01 100644 --- a/sys/arch/mvmeppc/mvmeppc/disksubr.c +++ b/sys/arch/mvmeppc/mvmeppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.40 2007/06/06 17:15:12 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.41 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -461,7 +461,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - goto done; + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -474,9 +474,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* Overwriting disk label? */ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && -#if LABELSECTOR != 0 bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && -#endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; @@ -489,6 +487,5 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bad: bp->b_flags |= B_ERROR; -done: return (-1); } diff --git a/sys/arch/sparc/sparc/disksubr.c b/sys/arch/sparc/sparc/disksubr.c index 9b7e8c15f3e..fad671b0e07 100644 --- a/sys/arch/sparc/sparc/disksubr.c +++ b/sys/arch/sparc/sparc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.52 2007/06/06 22:14:31 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.53 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.16 1996/04/28 20:25:59 thorpej Exp $ */ /* @@ -274,6 +274,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); + int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART]), lp) + + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); /* avoid division by zero */ @@ -288,7 +290,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - return (0); + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -303,8 +305,9 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* XXX should also protect bootstrap in first 8K */ /* XXX this assumes everything <=LABELSECTOR is label! */ /* But since LABELSECTOR is 0, that's ok for now. */ - if ((bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= LABELSECTOR) && - ((bp->b_flags & B_READ) == 0) && (wlabel == 0)) { + if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && + bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && + (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } @@ -313,6 +316,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bp->b_cylinder = (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp)) / lp->d_secpercyl; return (1); + bad: bp->b_flags |= B_ERROR; return (-1); diff --git a/sys/arch/sparc64/sparc64/disksubr.c b/sys/arch/sparc64/sparc64/disksubr.c index c12b448aa80..4670ab4d780 100644 --- a/sys/arch/sparc64/sparc64/disksubr.c +++ b/sys/arch/sparc64/sparc64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.31 2007/06/06 22:14:32 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.32 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk Exp $ */ /* @@ -273,6 +273,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, { #define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); + int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[RAW_PART]), lp) + + LABELSECTOR; int sz = howmany(bp->b_bcount, DEV_BSIZE); /* avoid division by zero */ @@ -287,7 +289,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; - return (0); + return (-1); } if (sz < 0) { /* If past end of disk, return EINVAL. */ @@ -302,8 +304,9 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* XXX should also protect bootstrap in first 8K */ /* XXX this assumes everything <=LABELSECTOR is label! */ /* But since LABELSECTOR is 0, that's ok for now. */ - if ((bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= LABELSECTOR) && - ((bp->b_flags & B_READ) == 0) && (wlabel == 0)) { + if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector && + bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && + (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } @@ -312,6 +315,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, bp->b_cylinder = (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp)) / lp->d_secpercyl; return (1); + bad: bp->b_flags |= B_ERROR; return (-1); diff --git a/sys/arch/vax/vax/disksubr.c b/sys/arch/vax/vax/disksubr.c index c6116937153..f7dd2ccea47 100644 --- a/sys/arch/vax/vax/disksubr.c +++ b/sys/arch/vax/vax/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.42 2007/06/06 16:42:07 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.43 2007/06/07 00:28:17 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1999/06/30 18:48:06 ragge Exp $ */ /* @@ -75,7 +75,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* if exactly at end of disk, return EOF. */ if (bp->b_blkno == maxsz) { bp->b_resid = bp->b_bcount; - return(0); + return (-1); } /* Otherwise, truncate request. */ sz = maxsz - bp->b_blkno; @@ -89,7 +89,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, /* overwriting disk label ? */ if (bp->b_blkno + DL_GETPOFFSET(p) <= LABELSECTOR + labelsector && - (bp->b_flags & B_READ) == 0 && wlabel == 0) { + bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector && + (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } |