This is the mail archive of the gdb-patches@sourceware.org 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: [RFC-v5] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)



> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pedro Alves
> Envoyà : jeudi 13 dÃcembre 2012 15:34
> Ã : Pierre Muller; GDB Patches
> Objet : Re: [RFC-v5] Fix .text section offset for windows DLL (was Calling
> __stdcall functions in the inferior)
> 
> On 12/13/2012 12:59 PM, Pierre Muller wrote:
> >> > There was also the point that section names in PE headers are stored in
> 8
> >> > character arrays, and are not necessarily zero-terminated --
> >> > get_pe_section_index
> >> > does strcmp without accounting for this (grep for SCNNMLEN in bfd).
> >   the section_name are copied using xstrdup from sec_name
> > char array of length 9, (indexes 0 to 8)
> > which is reset using memset for each section.
> >   only the indexes 0to 7 are possibly modified by the bfd_bread call,
> > so that sec_name[8] always should remain a valid termination of the
> string, no?
> 
> I see now, thanks.  I think this would make the code a tiny bit clearer.
> WDYT?

  Yes, you are right...

  Maybe removing the memset before and replacing it by a
  sec_name[SCNNMLEN] = '\0';
  after the call to bfd_bread
would make it even more clear that you
always get a nicely zero terminated string...

Pierre

 
> 2012-12-13  Pedro Alves  <palves@redhat.com>
> 
> 	* coff-pe-read.c (read_pe_exported_syms): Use SCNNMLEN instead of
> 	hardcoded 8.
> 
> ---
> 
>  gdb/coff-pe-read.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
> index 10bba78..aa4903a 100644
> --- a/gdb/coff-pe-read.c
> +++ b/gdb/coff-pe-read.c
> @@ -464,12 +464,12 @@ read_pe_exported_syms (struct objfile *objfile)
>        unsigned long vsize = pe_get32 (dll, secptr1 + 8);
>        unsigned long vaddr = pe_get32 (dll, secptr1 + 12);
>        unsigned long characteristics = pe_get32 (dll, secptr1 + 36);
> -      char sec_name[9];
> +      char sec_name[SCNNMLEN + 1];
>        int sectix;
> 
>        memset (sec_name, 0, sizeof (sec_name));
>        bfd_seek (dll, (file_ptr) secptr1 + 0, SEEK_SET);
> -      bfd_bread (sec_name, (bfd_size_type) 8, dll);
> +      bfd_bread (sec_name, (bfd_size_type) SCNNMLEN, dll);
> 
>        sectix = read_pe_section_index (sec_name);
> 



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