From 37c4b4161f69961dbcefc2220e7a0468fb4d1387 Mon Sep 17 00:00:00 2001 From: ae Date: Sun, 8 May 2011 12:16:39 +0000 Subject: [PATCH] Limit number of sectors that can be addressed. Reject table if blkcount from metadata is greater than provider. --- sys/geom/part/g_part_apm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/geom/part/g_part_apm.c b/sys/geom/part/g_part_apm.c index 9806bb862790..cd318c75f7fd 100644 --- a/sys/geom/part/g_part_apm.c +++ b/sys/geom/part/g_part_apm.c @@ -255,7 +255,7 @@ g_part_apm_create(struct g_part_table *basetable, struct g_part_parms *gpp) return (ENOSPC); /* APM uses 32-bit LBAs. */ - last = MIN(pp->mediasize / pp->sectorsize, 0xffffffff) - 1; + last = MIN(pp->mediasize / pp->sectorsize, UINT32_MAX) - 1; basetable->gpt_first = 2 + basetable->gpt_entries; basetable->gpt_last = last; @@ -398,6 +398,8 @@ g_part_apm_probe(struct g_part_table *basetable, struct g_consumer *cp) g_free(buf); if (table->ddr.ddr_blksize != pp->sectorsize) return (ENXIO); + if (table->ddr.ddr_blkcount > pp->mediasize / pp->sectorsize) + return (ENXIO); } else { /* * Check for Tivo drives, which have no DDR and a different @@ -412,7 +414,8 @@ g_part_apm_probe(struct g_part_table *basetable, struct g_consumer *cp) } table->ddr.ddr_sig = APM_DDR_SIG; /* XXX */ table->ddr.ddr_blksize = pp->sectorsize; /* XXX */ - table->ddr.ddr_blkcount = pp->mediasize / pp->sectorsize;/* XXX */ + table->ddr.ddr_blkcount = + MIN(pp->mediasize / pp->sectorsize, UINT32_MAX); table->tivo_series1 = 1; g_free(buf); }