This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH-bfd] i386-mingw32-ld crash on x86_64 linux
On Thu, Apr 16, 2009 at 09:41:35PM -0500, Peter O'Gorman wrote:
> Index: bfd/peXXigen.c
> ===================================================================
> --- bfd/peXXigen.c.orig 2008-07-30 04:34:56.000000000 +0000
> +++ bfd/peXXigen.c 2009-04-17 02:19:12.221139740 +0000
> @@ -138,7 +138,7 @@
>
> for (sec = abfd->sections; sec; sec = sec->next)
> {
> - if (strcmp (sec->name, in->n_name) == 0)
> + if (strncmp (sec->name, in->n_name, SYMNMLEN) == 0)
This isn't quite right. If in->n_name is not 0 terminated then you
could match the wrong section.
> {
> in->n_scnum = sec->target_index;
> break;
> @@ -157,10 +157,10 @@
> if (unused_section_number <= sec->target_index)
> unused_section_number = sec->target_index + 1;
>
> - name = bfd_alloc (abfd, (bfd_size_type) strlen (in->n_name) + 10);
> + name = bfd_alloc (abfd, (bfd_size_type) SYMNMLEN + 1);
Better to use char[SYMNMLEN + 1] rather than bfd_alloc.
> if (name == NULL)
> return;
> - strcpy (name, in->n_name);
> + strncpy (name, in->n_name, SYMNMLEN);
This also isn't quite correct. You want
strncpy (name, in->n_name, SYMNMLEN);
name[SYMNMLEN] = '\0';
So, something like the following. I won't commit this as it's
untested, and I'm not sure whether the ext->e.e_name[0] == 0 case
ought to be handled.
Index: bfd/peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.49
diff -u -p -r1.49 peXXigen.c
--- bfd/peXXigen.c 6 Apr 2009 16:48:36 -0000 1.49
+++ bfd/peXXigen.c 17 Apr 2009 03:59:32 -0000
@@ -129,6 +129,8 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void *
they will be handled somewhat correctly in the bfd code. */
if (in->n_sclass == C_SECTION)
{
+ char name[SYMNMLEN + 1];
+
in->n_value = 0x0;
/* Create synthetic empty sections as needed. DJ */
@@ -136,31 +138,23 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void *
{
asection *sec;
- for (sec = abfd->sections; sec; sec = sec->next)
- {
- if (strcmp (sec->name, in->n_name) == 0)
- {
- in->n_scnum = sec->target_index;
- break;
- }
- }
+ strncpy (name, in->n_name, SYMNMLEN);
+ name[SYMNMLEN] = '\0';
+ sec = bfd_get_section_by_name (abfd, name);
+ if (sec != NULL)
+ in->n_scnum = sec->target_index;
}
if (in->n_scnum == 0)
{
int unused_section_number = 0;
asection *sec;
- char *name;
flagword flags;
for (sec = abfd->sections; sec; sec = sec->next)
if (unused_section_number <= sec->target_index)
unused_section_number = sec->target_index + 1;
- name = bfd_alloc (abfd, (bfd_size_type) strlen (in->n_name) + 10);
- if (name == NULL)
- return;
- strcpy (name, in->n_name);
flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_DATA | SEC_LOAD;
sec = bfd_make_section_anyway_with_flags (abfd, name, flags);
--
Alan Modra
Australia Development Lab, IBM