All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix an infinite loop with a corrupted pc partition table
@ 2009-07-24 16:58 Felix Zielcke
  2009-07-24 19:24 ` Felix Zielcke
  2009-07-24 19:56 ` Pavel Roskin
  0 siblings, 2 replies; 19+ messages in thread
From: Felix Zielcke @ 2009-07-24 16:58 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 892 bytes --]

With this [0] partition table grub-probe currently loops forever:

kern/disk.c:389: Reading `hd1'...
partmap/pc.c:142: partition 0: flag 0x0, type 0x5, start 0x0, len
0x11177330
partmap/pc.c:142: partition 1: flag 0x0, type 0x0, start 0x0, len 0x0
partmap/pc.c:142: partition 2: flag 0x0, type 0x0, start 0x0, len 0x0
partmap/pc.c:142: partition 3: flag 0x0, type 0x0, start 0x0, len 0x0
kern/disk.c:389: Reading `hd1'...
partmap/pc.c:142: partition 0: flag 0x0, type 0x5, start 0x0, len
0x11177330
partmap/pc.c:142: partition 1: flag 0x0, type 0x0, start 0x0, len 0x0
partmap/pc.c:142: partition 2: flag 0x0, type 0x0, start 0x0, len 0x0
partmap/pc.c:142: partition 3: flag 0x0, type 0x0, start 0x0, len 0x0
[...]

This patch fixes it, but probable there's a better fix.


[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=corrupt-table.dat;att=1;bug=519223

-- 
Felix Zielcke

[-- Attachment #2: corrupted_partmap.diff --]
[-- Type: text/x-patch, Size: 1090 bytes --]

2009-07-24  Felix Zielcke  <fzielcke@z-51.de>

	* 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;
 }

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2009-09-11 21:50 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-24 16:58 [PATCH] fix an infinite loop with a corrupted pc partition table Felix Zielcke
2009-07-24 19:24 ` Felix Zielcke
2009-07-24 20:28   ` Pavel Roskin
2009-07-24 20:46     ` Vladimir 'phcoder' Serbinenko
2009-07-25 16:36   ` Robert Millan
2009-07-25 16:56     ` Vladimir 'phcoder' Serbinenko
2009-07-25 22:06       ` Pavel Roskin
2009-07-25 22:35         ` Vladimir 'phcoder' Serbinenko
2009-07-25 22:58           ` Vladimir 'phcoder' Serbinenko
2009-07-25 23:20             ` Vladimir 'phcoder' Serbinenko
2009-07-26  6:49               ` Felix Zielcke
2009-07-28 17:55             ` Robert Millan
2009-08-23 15:40               ` Vladimir 'phcoder' Serbinenko
2009-08-28 17:30                 ` Vladimir 'phcoder' Serbinenko
2009-09-11 21:50                 ` Pavel Roskin
2009-07-24 19:56 ` Pavel Roskin
2009-07-24 20:35   ` Vladimir 'phcoder' Serbinenko
2009-07-24 21:03     ` Pavel Roskin
2009-07-25 10:48       ` Vladimir 'phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.