This is the mail archive of the binutils@sources.redhat.com 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]

readelf: Handle corrupt corefiles


Hi Guys,

  I am checking in the patch below to fix the recently reported
  problem of readelf core dumping when given a badly formatted core
  file to display.

Cheers
        Nick

2002-04-16  Nick Clifton  <nickc@cambridge.redhat.com>

	* readelf.c (process_corefile_note_segment): Catch corrupt notes
	and display a warning message, then exit the loop.

Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.154
diff -c -3 -p -w -r1.154 readelf.c
*** binutils/readelf.c	21 Mar 2002 05:00:58 -0000	1.154
--- binutils/readelf.c	16 Apr 2002 14:57:04 -0000
*************** process_corefile_note_segment (file, off
*** 9440,9445 ****
--- 9428,9434 ----
  
    while (external < (Elf_External_Note *)((char *) pnotes + length))
      {
+       Elf_External_Note * next;
        Elf32_Internal_Note inote;
        char * temp = NULL;
  
*************** process_corefile_note_segment (file, off
*** 9450,9456 ****
        inote.descdata = inote.namedata + align_power (inote.namesz, 2);
        inote.descpos  = offset + (inote.descdata - (char *) pnotes);
  
!       external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
  
        /* Verify that name is null terminated.  It appears that at least
  	 one version of Linux (RedHat 6.0) generates corefiles that don't
--- 9439,9456 ----
        inote.descdata = inote.namedata + align_power (inote.namesz, 2);
        inote.descpos  = offset + (inote.descdata - (char *) pnotes);
  
!       next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
! 
!       if (((char *) next) > (((char *) pnotes) + length))
! 	{
! 	  warn (_("corrupt note found at offset %x into core notes\n"),
! 		((char *) external) - ((char *) pnotes));
! 	  warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
! 		inote.type, inote.namesz, inote.descsz);
! 	  break;
! 	}
! 
!       external = next;
  
        /* Verify that name is null terminated.  It appears that at least
  	 one version of Linux (RedHat 6.0) generates corefiles that don't


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