diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2009-06-05 00:41:14 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2009-06-05 00:41:14 +0000 |
commit | f6c84e623aa405ce40dc494e32099f4d621e8c87 (patch) | |
tree | 2dbf83713ba41acc4db134645c897281b2870fb4 /sys | |
parent | 544aa026f27246aa9a6f3fd57a69101b9adbf4fa (diff) |
Clamp the ending bound to the size of the disk. This makes disklabel -A
still do the right thing if the MBR has a lie in it
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/macppc/macppc/disksubr.c | 11 | ||||
-rw-r--r-- | sys/arch/socppc/socppc/disksubr.c | 11 | ||||
-rw-r--r-- | sys/kern/subr_disk.c | 6 |
3 files changed, 15 insertions, 13 deletions
diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index 494ea445e79..63dfc2e981d 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.62 2009/06/04 21:13:02 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.63 2009/06/05 00:41:12 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -106,7 +106,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), struct disklabel *lp, int *partoffp, int spoofonly) { int i, part_cnt, n, hfspartoff = -1; - u_int hfspartlen; + u_int64_t hfspartend; struct part_map_entry *part; /* First check for a DPME (HFS) disklabel */ @@ -143,7 +143,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (strcmp(part->pmPartType, PART_TYPE_OPENBSD) == 0) { hfspartoff = part->pmPyPartStart - LABELSECTOR; - hfspartlen = part->pmPartBlkCnt; + hfspartend = hfspartoff + part->pmPartBlkCnt; if (partoffp) { *partoffp = hfspartoff; return (NULL); @@ -164,7 +164,8 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), } DL_SETBSTART(lp, hfspartoff); - DL_SETBEND(lp, hfspartoff + hfspartlen); + DL_SETBEND(lp, hfspartend < DL_GETDSIZE(lp) ? hfspartend : + DL_GETDSIZE(lp)); } if (hfspartoff == -1) @@ -182,7 +183,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), return("disk label I/O error"); return checkdisklabel(bp->b_data + LABELOFFSET, lp, hfspartoff, - hfspartoff + hfspartlen); + hfspartend); } /* diff --git a/sys/arch/socppc/socppc/disksubr.c b/sys/arch/socppc/socppc/disksubr.c index 4ecf30af00a..c7c459d0a64 100644 --- a/sys/arch/socppc/socppc/disksubr.c +++ b/sys/arch/socppc/socppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.6 2009/06/04 21:13:02 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.7 2009/06/05 00:41:13 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -106,7 +106,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), struct disklabel *lp, int *partoffp, int spoofonly) { int i, part_cnt, n, hfspartoff = -1; - u_int hfspartlen; + u_int64_t hfspartend; struct part_map_entry *part; /* First check for a DPME (HFS) disklabel */ @@ -143,7 +143,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (strcmp(part->pmPartType, PART_TYPE_OPENBSD) == 0) { hfspartoff = part->pmPyPartStart - LABELSECTOR; - hfspartlen = part->pmPartBlkCnt; + hfspartend = hfspartoff + part->pmPartBlkCnt; if (partoffp) { *partoffp = hfspartoff; return (NULL); @@ -164,7 +164,8 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), } DL_SETBSTART(lp, hfspartoff); - DL_SETBEND(lp, hfspartoff + hfspartlen); + DL_SETBEND(lp, hfspartend < DL_GETDSIZE(lp) ? hfspartend : + DL_GETDSIZE(lp)); } if (hfspartoff == -1) @@ -182,7 +183,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), return("disk label I/O error"); return checkdisklabel(bp->b_data + LABELOFFSET, lp, hfspartoff, - hfspartoff + hfspartlen); + hfspartend); } /* diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 435db496073..2508c186ce1 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.92 2009/06/04 21:13:02 deraadt Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.93 2009/06/05 00:41:13 deraadt Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -361,7 +361,7 @@ checkdisklabel(void *rlp, struct disklabel *lp, DL_SETPSIZE(&lp->d_partitions[RAW_PART], disksize); DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0); DL_SETBSTART(lp, boundstart); - DL_SETBEND(lp, boundend); + DL_SETBEND(lp, boundend < DL_GETDSIZE(lp) ? boundend : DL_GETDSIZE(lp)); lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); @@ -576,7 +576,7 @@ donot: } notfat: DL_SETBSTART(lp, dospartoff); - DL_SETBEND(lp, dospartend); + DL_SETBEND(lp, dospartend < DL_GETDSIZE(lp) ? dospartend : DL_GETDSIZE(lp)); /* record the OpenBSD partition's placement for the caller */ if (partoffp) |