2009-07-24 Felix Zielcke * partmap/pc.c (pc_partition_map_iterate): Don't loop forever in case the partition table is corrupted. diff --git a/partmap/pc.c b/partmap/pc.c index 6f68ecf..0271311 100644 --- a/partmap/pc.c +++ b/partmap/pc.c @@ -97,6 +97,7 @@ pc_partition_map_iterate (grub_disk_t disk, struct grub_pc_partition_mbr mbr; struct grub_pc_partition_disk_label label; struct grub_disk raw; + int loop; /* Enforce raw disk access. */ raw = *disk; @@ -108,11 +109,13 @@ pc_partition_map_iterate (grub_disk_t disk, p.data = &pcdata; p.partmap = &grub_pc_partition_map; - while (1) + loop = 0; + while (loop < 100) { int i; struct grub_pc_partition_entry *e; + loop++; /* Read the MBR. */ if (grub_disk_read (&raw, p.offset, 0, sizeof (mbr), &mbr)) goto finish; @@ -221,6 +224,9 @@ pc_partition_map_iterate (grub_disk_t disk, break; } + if (loop == 100) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "Corrupted partition table found."); + finish: return grub_errno; }