summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-29 01:12:22 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-29 01:12:22 +0000
commit34fa754d3ed747cdda822208ebd5e45432353638 (patch)
treecb8d3f4102c66eef93780dc61ef159565de32dc7 /sys/arch
parent190b9bd93e9e482b76c39160dfc0cae2ff450568 (diff)
ignore partitions larger than device, as an attempt to ignore floppies without MBR
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/arc/arc/disksubr.c4
-rw-r--r--sys/arch/i386/i386/disksubr.c34
-rw-r--r--sys/arch/i386/include/disklabel.h17
3 files changed, 37 insertions, 18 deletions
diff --git a/sys/arch/arc/arc/disksubr.c b/sys/arch/arc/arc/disksubr.c
index bec7bfd0c0c..06af1ceec90 100644
--- a/sys/arch/arc/arc/disksubr.c
+++ b/sys/arch/arc/arc/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.16 1997/09/23 12:46:38 pefo Exp $ */
+/* $OpenBSD: disksubr.c,v 1.17 1997/09/29 01:12:20 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -180,6 +180,8 @@ donot:
for (dp2=dp, i=0; i < NDOSPART && n < 8; i++, dp2++) {
struct partition *pp = &lp->d_partitions[8+n];
+ if (get_le(&dp2->dp_size) > lp->d_secperunit)
+ continue;
if (get_le(&dp2->dp_size))
pp->p_size = get_le(&dp2->dp_size);
if (get_le(&dp2->dp_start))
diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c
index 436f7b05fbe..16d0b78ea8f 100644
--- a/sys/arch/i386/i386/disksubr.c
+++ b/sys/arch/i386/i386/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.25 1997/08/08 21:46:43 niklas Exp $ */
+/* $OpenBSD: disksubr.c,v 1.26 1997/09/29 01:12:21 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -142,12 +142,12 @@ readdisklabel(dev, strat, lp, osdep)
/* Search for our MBR partition */
for (dp2=dp, i=0; i < NDOSPART && ourpart == -1;
i++, dp2++)
- if (dp2->dp_size &&
+ if (get_le(&dp2->dp_size) &&
dp2->dp_typ == DOSPTYP_OPENBSD)
ourpart = i;
for (dp2=dp, i=0; i < NDOSPART && ourpart == -1;
i++, dp2++)
- if (dp2->dp_size &&
+ if (get_le(&dp2->dp_size) &&
dp2->dp_typ == DOSPTYP_386BSD)
ourpart = i;
if (ourpart == -1)
@@ -157,13 +157,13 @@ readdisklabel(dev, strat, lp, osdep)
* for SCSI/IDE, cylinder for ESDI/ST506/RLL
*/
dp2 = &dp[ourpart];
- dospartoff = dp2->dp_start + part_blkno;
+ dospartoff = get_le(&dp2->dp_start) + part_blkno;
cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect);
/* XXX build a temporary disklabel */
- lp->d_partitions[0].p_size = dp2->dp_size;
- lp->d_partitions[0].p_offset = dp2->dp_start +
- part_blkno;
+ lp->d_partitions[0].p_size = get_le(&dp2->dp_size);
+ lp->d_partitions[0].p_offset =
+ get_le(&dp2->dp_start) + part_blkno;
if (lp->d_ntracks == 0)
lp->d_ntracks = dp2->dp_ehd + 1;
if (lp->d_nsectors == 0)
@@ -180,11 +180,13 @@ donot:
for (dp2=dp, i=0; i < NDOSPART && n < 8; i++, dp2++) {
struct partition *pp = &lp->d_partitions[8+n];
- if (dp2->dp_size)
- pp->p_size = dp2->dp_size;
- if (dp2->dp_start)
+ if (get_le(&dp2->dp_size) > lp->d_secperunit)
+ continue;
+ if (get_le(&dp2->dp_size))
+ pp->p_size = get_le(&dp2->dp_size);
+ if (get_le(&dp2->dp_start))
pp->p_offset =
- dp2->dp_start + part_blkno;
+ get_le(&dp2->dp_start) + part_blkno;
switch (dp2->dp_typ) {
case DOSPTYP_UNUSED:
@@ -216,9 +218,9 @@ donot:
n++;
break;
case DOSPTYP_EXTEND:
- part_blkno = dp2->dp_start + extoff;
+ part_blkno = get_le(&dp2->dp_start) + extoff;
if (!extoff)
- extoff = dp2->dp_start;
+ extoff = get_le(&dp2->dp_start);
wander = 1;
break;
default:
@@ -408,10 +410,10 @@ writedisklabel(dev, strat, lp, osdep)
NDOSPART * sizeof(*dp));
for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++)
- if (dp2->dp_size && dp2->dp_typ == DOSPTYP_OPENBSD)
+ if (get_le(&dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD)
ourpart = i;
for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++)
- if (dp2->dp_size && dp2->dp_typ == DOSPTYP_386BSD)
+ if (get_le(&dp2->dp_size) && dp2->dp_typ == DOSPTYP_386BSD)
ourpart = i;
if (ourpart != -1) {
@@ -421,7 +423,7 @@ writedisklabel(dev, strat, lp, osdep)
* need sector address for SCSI/IDE,
* cylinder for ESDI/ST506/RLL
*/
- dospartoff = dp2->dp_start;
+ dospartoff = get_le(&dp2->dp_start);
cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect);
}
}
diff --git a/sys/arch/i386/include/disklabel.h b/sys/arch/i386/include/disklabel.h
index baaac17bf17..fe2a53c5118 100644
--- a/sys/arch/i386/include/disklabel.h
+++ b/sys/arch/i386/include/disklabel.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.h,v 1.14 1997/08/29 19:44:10 mickey Exp $ */
+/* $OpenBSD: disklabel.h,v 1.15 1997/09/29 01:12:19 deraadt Exp $ */
/* $NetBSD: disklabel.h,v 1.3 1996/03/09 20:52:54 ghudson Exp $ */
/*
@@ -93,4 +93,19 @@ struct cpu_disklabel {
#define DPSECT(s) ((s) & 0x3f)
#define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2))
+static __inline u_int32_t get_le __P((void *));
+
+static __inline u_int32_t
+get_le(p)
+ void *p;
+{
+ u_int8_t *_p = (u_int8_t *)p;
+ u_int32_t x;
+ x = _p[0];
+ x |= _p[1] << 8;
+ x |= _p[2] << 16;
+ x |= _p[3] << 24;
+ return x;
+}
+
#endif /* _MACHINE_DISKLABEL_H_ */