Re: [PATCH] partitions/msdos.c

From: Linus Torvalds
Date: Sat Feb 26 2005 - 17:35:43 EST




On Sat, 26 Feb 2005, Linus Torvalds wrote:
>
> Would it not make more sense to just sanity-check the size itself, and
> throw it out if the partition size (plus start) is bigger than the disk
> size?

Something like this (TOTALLY UNTESTED AS USUAL!)?

What does fdisk and other tools do on that disk? Just out of interest..

Linus

---
===== fs/partitions/msdos.c 1.26 vs edited =====
--- 1.26/fs/partitions/msdos.c 2004-11-09 12:43:17 -08:00
+++ edited/fs/partitions/msdos.c 2005-02-26 14:33:33 -08:00
@@ -381,6 +381,7 @@
int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int sector_size = bdev_hardsect_size(bdev) / 512;
+ sector_t nr_sectors;
Sector sect;
unsigned char *data;
struct partition *p;
@@ -426,11 +427,12 @@
* On the second pass look inside *BSD, Unixware and Solaris partitions.
*/

+ nr_sectors = get_capacity(bdev->bd_disk);
state->next = 5;
for (slot = 1 ; slot <= 4 ; slot++, p++) {
u32 start = START_SECT(p)*sector_size;
u32 size = NR_SECTS(p)*sector_size;
- if (!size)
+ if (!size || size > nr_sectors)
continue;
if (is_extended_partition(p)) {
/* prevent someone doing mkfs or mkswap on an
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/