[RFA/Darwin v2] Avoid a crash when working on OSO without symbol.

Xavier Roirand roirand@adacore.com
Thu Mar 1 11:38:00 GMT 2018


From: Tristan Gingold <gingold@adacore.com>

When reading OSO file without symbol, macho_add_oso_symfile
may crash when creating empty hash table.

This patch fix this.

gdb/ChangeLog: (Tristan Gingold <gingold@adacore.com>)

	* machoread.c (macho_add_oso_symfile): Handle case
	when OSO does not have symbol.
---
 gdb/ChangeLog   | 6 ++++++
 gdb/machoread.c | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 59265157b4..050376a696 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2018-02-27  Tristan Gingold  <gingold@adacore.com>
+
+	Pushed by Xavier Roirand <roirand@adacore.com>
+	* machoread.c (macho_add_oso_symfile): Handle case when
+	OSO does not have symbol.
+
 2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>
 	    Simon Marchi  <simon.marchi@polymtl.ca>
 
diff --git a/gdb/machoread.c b/gdb/machoread.c
index b270675d61..b00ef133a9 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -579,6 +579,11 @@ macho_add_oso_symfile (oso_el *oso, const gdb_bfd_ref_ptr &abfd,
                 {
                   struct macho_sym_hash_entry *ent;
 
+		  /* Nothing to do if there is no symbol (and avoid a crash
+		     while creating an empty hash table).  */
+		  if (oso->nbr_syms == 0)
+		    continue;
+
                   ent = (struct macho_sym_hash_entry *)
                     bfd_hash_lookup (&table, sym->name, FALSE, FALSE);
                   if (ent != NULL)
-- 
2.14.3 (Apple Git-98)



More information about the Gdb-patches mailing list