This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Fix seg fault displaying corrupt DWARF information


Hi Guys,

  In the course of some other work I managed to generate a file
  containing a corrupt .debug_info section.  When I ran "readelf -w"
  on it, readelf core dumped.  So I am checking in the attached patch
  to fix the problem, which was the code not checking to see if the
  load/parse of the .debug_info section had succeeded.

Cheers
  Nick

binutils/ChangeLog
2008-01-14  Nick Clifton  <nickc@redhat.com>

	* dwarf.c (process_debug_info): Include the CU offset and corrupt
	version value when reporting unrecognised DWARF version numbers.
	(load_debug_info): Remember a failed attempt to load and parse the
	.debug_info section and do not repeat such attempts.
	(display_debug_lines): Check the return value from load_debug_info
	and return whilst displaying a warning message if the load failed.
	(display_debug_loc): Likewise.
	(display_debug_ranges): Likewise.

Index: binutils/dwarf.c
===================================================================
RCS file: /cvs/src/src/binutils/dwarf.c,v
retrieving revision 1.23
diff -c -3 -p -r1.23 dwarf.c
*** binutils/dwarf.c	4 Jan 2008 09:53:41 -0000	1.23
--- binutils/dwarf.c	14 Jan 2008 12:20:26 -0000
*************** process_debug_info (struct dwarf_section
*** 1841,1847 ****
  
        if (compunit.cu_version != 2 && compunit.cu_version != 3)
  	{
! 	  warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
  	  continue;
  	}
  
--- 1841,1848 ----
  
        if (compunit.cu_version != 2 && compunit.cu_version != 3)
  	{
! 	  warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
! 		cu_offset, compunit.cu_version);
  	  continue;
  	}
  
*************** load_debug_info (void * file)
*** 1985,1990 ****
--- 1986,1996 ----
    last_pointer_size = 0;
    warned_about_missing_comp_units = FALSE;
  
+   /* If we have already tried and failed to load the .debug_info
+      section then do not bother to repear the task.  */
+   if (num_debug_info_entries == (unsigned) -1)
+     return 0;
+ 
    /* If we already have the information there is nothing else to do.  */
    if (num_debug_info_entries > 0)
      return num_debug_info_entries;
*************** load_debug_info (void * file)
*** 1992,1999 ****
    if (load_debug_section (info, file)
        && process_debug_info (&debug_displays [info].section, file, 1))
      return num_debug_info_entries;
!   else
!     return 0;
  }
  
  static int
--- 1998,2006 ----
    if (load_debug_section (info, file)
        && process_debug_info (&debug_displays [info].section, file, 1))
      return num_debug_info_entries;
! 
!   num_debug_info_entries = (unsigned) -1;
!   return 0;
  }
  
  static int
*************** display_debug_lines (struct dwarf_sectio
*** 2006,2012 ****
    printf (_("\nDump of debug contents of section %s:\n\n"),
  	  section->name);
  
!   load_debug_info (file);
  
    while (data < end)
      {
--- 2013,2024 ----
    printf (_("\nDump of debug contents of section %s:\n\n"),
  	  section->name);
  
!   if (load_debug_info (file) == 0)
!     {
!       warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
! 	    section->name);
!       return 0;
!     }
  
    while (data < end)
      {
*************** display_debug_loc (struct dwarf_section 
*** 2501,2507 ****
        return 0;
      }
  
!   load_debug_info (file);
  
    /* Check the order of location list in .debug_info section. If
       offsets of location lists are in the ascending order, we can
--- 2513,2524 ----
        return 0;
      }
  
!   if (load_debug_info (file) == 0)
!     {
!       warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
! 	    section->name);
!       return 0;
!     }
  
    /* Check the order of location list in .debug_info section. If
       offsets of location lists are in the ascending order, we can
*************** display_debug_ranges (struct dwarf_secti
*** 2876,2882 ****
        return 0;
      }
  
!   load_debug_info (file);
  
    /* Check the order of range list in .debug_info section. If
       offsets of range lists are in the ascending order, we can
--- 2893,2904 ----
        return 0;
      }
  
!   if (load_debug_info (file) == 0)
!     {
!       warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
! 	    section->name);
!       return 0;
!     }
  
    /* Check the order of range list in .debug_info section. If
       offsets of range lists are in the ascending order, we can

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]