public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add "build_id" to struct bfd_preserve
@ 2016-09-07  8:35 Bhushan Attarde
  2016-09-14 12:50 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Bhushan Attarde @ 2016-09-07  8:35 UTC (permalink / raw)
  To: binutils; +Cc: gdb-patches, Maciej.Rozycki, Jaydeep.Patil, Bhushan Attarde

  Currently the "build_id" field of "struct bfd" is not preserved by
"struct bfd_preserve" when "bfd_check_format_matches" is going through all
target vectors trying to find a compatible target vector. This leads to a
segmentation fault in GDB.

  Consider a case where one compatible target vector has already been found (so
the subset of bfd state is saved in struct bfd_preserve) and then an attempt to
find a better match fails after it has modified bfd's build_id pointer. Since
this attempt is failed, all its side effects will be undone and all memory
allocations done by this vector will be free'd. This will eventually free the
memory block that build_id pointer is pointing to. This free'd block then gets
reallocated and used for storing something else -- leaving build_id pointing to
incorrect contents.

 This patch adds "build_id" pointer to "struct bfd_preserve" so that it will be
preserved on success which can then be recoverable on failure.

bfd/ChangeLog:

	* format.c (struct bfd_preserve): New "build_id" field.
	(bfd_preserve_save): Save "build_id".
	(bfd_preserve_restore): Restore "build_id".
---
 bfd/format.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/bfd/format.c b/bfd/format.c
index f34b1d4..459aa54 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -104,6 +104,7 @@ struct bfd_preserve
   struct bfd_section *section_last;
   unsigned int section_count;
   struct bfd_hash_table section_htab;
+  const struct bfd_build_id *build_id;
 };
 
 /* When testing an object for compatibility with a particular target
@@ -125,6 +126,7 @@ bfd_preserve_save (bfd *abfd, struct bfd_preserve *preserve)
   preserve->section_last = abfd->section_last;
   preserve->section_count = abfd->section_count;
   preserve->section_htab = abfd->section_htab;
+  preserve->build_id = abfd->build_id;
   preserve->marker = bfd_alloc (abfd, 1);
   if (preserve->marker == NULL)
     return FALSE;
@@ -158,6 +160,7 @@ bfd_preserve_restore (bfd *abfd, struct bfd_preserve *preserve)
   abfd->sections = preserve->sections;
   abfd->section_last = preserve->section_last;
   abfd->section_count = preserve->section_count;
+  abfd->build_id = preserve->build_id;
 
   /* bfd_release frees all memory more recently bfd_alloc'd than
      its arg, as well as its arg.  */
-- 
1.9-rc2

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add "build_id" to struct bfd_preserve
  2016-09-07  8:35 [PATCH] Add "build_id" to struct bfd_preserve Bhushan Attarde
@ 2016-09-14 12:50 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2016-09-14 12:50 UTC (permalink / raw)
  To: Bhushan Attarde, binutils; +Cc: gdb-patches, Maciej.Rozycki, Jaydeep.Patil

Hi Bhushan,

> bfd/ChangeLog:
> 
> 	* format.c (struct bfd_preserve): New "build_id" field.
> 	(bfd_preserve_save): Save "build_id".
> 	(bfd_preserve_restore): Restore "build_id".
 
Approved and applied.

Cheers
  Nick

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-14 12:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-07  8:35 [PATCH] Add "build_id" to struct bfd_preserve Bhushan Attarde
2016-09-14 12:50 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).