This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC-v5] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)
- From: Pedro Alves <palves at redhat dot com>
- To: Pierre Muller <pierre dot muller at ics-cnrs dot unistra dot fr>, GDB Patches <gdb-patches at sourceware dot org>
- Date: Thu, 13 Dec 2012 14:33:38 +0000
- Subject: Re: [RFC-v5] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)
- References: <20121024194517.GK3555@adacore.com> <011901cdb2ab$48076b90$d81642b0$@muller@ics-cnrs.unistra.fr> <20121105171121.GA2972@adacore.com> <50991f5f.8382440a.1100.ffff82abSMTPIN_ADDED@mx.google.com> <509ABA17.30507@redhat.com> <000301cdbd96$f5cd9f10$e168dd30$@muller@ics-cnrs.unistra.fr> <20121122173019.GF9964@adacore.com> <15690.5992342674$1353883881@news.gmane.org> <87624si9ur.fsf@fleche.redhat.com> <001501cdccaf$ad85e9b0$0891bd10$@muller@ics-cnrs.unistra.fr> <20121207071035.GG31477@adacore.com> <50C20A66.70002@gmail.com> <29545.4593528577$1354894901@news.gmane.org> <50C21696.7040006@gmail.com> <50c21914.a750420a.2ec3.ffffe4ffSMTPIN_ADDED_BROKEN@mx.google.com> <50C222D5.4000802@redhat.com> <50C22C20.8090906@redhat.com> <008101cdd920$907e7580$b17b6080$@muller@ics-cnrs.unistra.fr> <50C9B6E0.1050709@redhat.com> <00a201cdd931$b0ee13f0$12ca3bd0$@muller@ics-cnrs.unistra.fr>
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?
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);