Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH,gdb]: ensures that cie ptr of an fda is a cie
@ 2011-07-04 18:19 Fawzi Mohamed
  2011-07-04 18:52 ` Joel Brobecker
  2011-07-05 16:26 ` [PATCH,gdb]: " Tom Tromey
  0 siblings, 2 replies; 17+ messages in thread
From: Fawzi Mohamed @ 2011-07-04 18:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: ext Tristan Gingold, André Pönitz

Here is a patch that ensures that cie pointer of a fda really points to a cie.

This avoids infinite loops if a fda cie pointer points to itself, as was the case on
mac when the mmaped read section was broken for fat binaries and returned 
invalid info (see http://sourceware.org/bugzilla/show_bug.cgi?id=11488 ).

This increases the robustness of gdb, so I think it is worthwhile to add.

Fawzi

2011-07-04 Fawzi Mohamed <fawzi.mohamed@nokia.com>

	* dwarf2-frame.c (decode_frame_entry, decode_frame_entry_1): ensure
	that cie pointer really points to a cie 

Index: gdb/dwarf2-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v
retrieving revision 1.125
diff -d -u -r1.125 dwarf2-frame.c
--- gdb/dwarf2-frame.c	4 Jul 2011 16:30:09 -0000	1.125
+++ gdb/dwarf2-frame.c	4 Jul 2011 17:39:29 -0000
@@ -1801,17 +1801,25 @@
 #define DW64_CIE_ID ~0
 #endif
 
+enum eh_frame_type {
+    eh_cie_type_id = 1,
+    eh_fde_type_id = 2,
+    eh_cie_or_fde_type_id = 3
+};
+
 static gdb_byte *decode_frame_entry (struct comp_unit *unit, gdb_byte *start,
 				     int eh_frame_p,
                                      struct dwarf2_cie_table *cie_table,
-                                     struct dwarf2_fde_table *fde_table);
+                                     struct dwarf2_fde_table *fde_table,
+                                     enum eh_frame_type entry_type);
 
 /* Decode the next CIE or FDE.  Return NULL if invalid input, otherwise
    the next byte to be processed.  */
 static gdb_byte *
 decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
                       struct dwarf2_cie_table *cie_table,
-                      struct dwarf2_fde_table *fde_table)
+                      struct dwarf2_fde_table *fde_table,
+                      enum eh_frame_type entry_type)
 {
   struct gdbarch *gdbarch = get_objfile_arch (unit->objfile);
   gdb_byte *buf, *end;
@@ -1862,6 +1870,8 @@
       char *augmentation;
       unsigned int cie_version;
 
+      gdb_assert ((entry_type & eh_cie_type_id)!=0);
+
       /* Record the offset into the .debug_frame section of this CIE.  */
       cie_pointer = start - unit->dwarf_frame_buffer;
 
@@ -2027,6 +2037,8 @@
       /* This is a FDE.  */
       struct dwarf2_fde *fde;
 
+      gdb_assert ((entry_type & eh_fde_type_id)!=0);
+
       /* In an .eh_frame section, the CIE pointer is the delta between the
 	 address within the FDE where the CIE pointer is stored and the
 	 address of the CIE.  Convert it to an offset into the .eh_frame
@@ -2048,7 +2060,8 @@
       if (fde->cie == NULL)
 	{
 	  decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer,
-			      eh_frame_p, cie_table, fde_table);
+			      eh_frame_p, cie_table, fde_table,
+			      eh_cie_type_id);
 	  fde->cie = find_cie (cie_table, cie_pointer);
 	}
 
@@ -2093,7 +2106,8 @@
 static gdb_byte *
 decode_frame_entry (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
                     struct dwarf2_cie_table *cie_table,
-                    struct dwarf2_fde_table *fde_table)
+                    struct dwarf2_fde_table *fde_table,
+                    enum eh_frame_type entry_type)
 {
   enum { NONE, ALIGN4, ALIGN8, FAIL } workaround = NONE;
   gdb_byte *ret;
@@ -2102,7 +2116,8 @@
   while (1)
     {
       ret = decode_frame_entry_1 (unit, start, eh_frame_p,
-                                  cie_table, fde_table);
+                                  cie_table, fde_table,entry_type,
+                                  entry_type);
       if (ret != NULL)
 	break;
 
@@ -2256,7 +2271,8 @@
           frame_ptr = unit->dwarf_frame_buffer;
           while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
             frame_ptr = decode_frame_entry (unit, frame_ptr, 1,
-                                            &cie_table, &fde_table);
+                                            &cie_table, &fde_table,
+                                            eh_cie_or_fde_type_id);
 
           if (cie_table.num_entries != 0)
             {


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

end of thread, other threads:[~2011-07-15 15:21 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-04 18:19 [PATCH,gdb]: ensures that cie ptr of an fda is a cie Fawzi Mohamed
2011-07-04 18:52 ` Joel Brobecker
2011-07-05 10:44   ` [PATCH,gdb, Update1]: " Fawzi Mohamed
2011-07-05 15:17     ` Joel Brobecker
2011-07-05 16:57       ` [PATCH,gdb, Update2]: " Fawzi Mohamed
2011-07-05 16:26 ` [PATCH,gdb]: " Tom Tromey
2011-07-06 14:45   ` [PATCH,gdb,Update3]: " Fawzi Mohamed
2011-07-06 18:16     ` Jan Kratochvil
2011-07-07 17:17       ` [PATCH,gdb,Update4]: " Fawzi Mohamed
2011-07-07 23:37         ` Tom Tromey
2011-07-11 17:19           ` [PATCH,gdb,Update6]: " Fawzi Mohamed
2011-07-11 21:52             ` Tom Tromey
2011-07-12 11:15               ` [PATCH,gdb,Update7]: " Fawzi Mohamed
2011-07-12 20:01                 ` Tom Tromey
2011-07-15 15:34                   ` FYI " Fawzi Mohamed
2011-07-07 18:48       ` [PATCH,gdb,Update5]: " Fawzi Mohamed
2011-07-07 19:38         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox