This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB 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]

Re: [RFA/PATCH] Fix recognition of NT_PRXFREG notes


On Thu, Jul 04, 2002 at 05:03:22PM +0200, Mark Kettenis wrote:
> Index: elf.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elf.c,v
> retrieving revision 1.152
> diff -u -p -r1.152 elf.c
> --- elf.c 4 Jul 2002 13:26:30 -0000 1.152
> +++ elf.c 4 Jul 2002 14:54:36 -0000
> @@ -6718,8 +6718,7 @@ elfcore_grok_note (abfd, note)
>  #endif
>  
>      case NT_PRXFPREG:		/* Linux SSE extension */
> -      if (note->namesz == 5
> -	  && ! strcmp (note->namedata, "LINUX"))
> +      if (strncmp (note->namedata, "LINUX", 5) == 0)
>  	return elfcore_grok_prxfpreg (abfd, note);
>        else
>  	return true;

Don't the alignment rules require that the name be padded out to a
multiple of 4 chars? (or 8 on 64 bit ELF files).  So you should have
'L','I','N','U','X','\0','\0','\0' and thus can use strcmp.  Also,
it's a good idea to check namesz before accessing namedata.  I'm
sure I can make your strncmp segfault by carefully crafting a
non-compliant note.

Hmm, on re-reading the ELF standard, I see the pad char isn't
specified.  :-(  But obviously the original strcmp worked, so the
pad from the kernel is zero.  Please use

      if (note->namesz >= 5
	  && strcmp (note->namedata, "LINUX") == 0)

and commit the patch.  Thanks.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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