[2/3] Clear static_links in reread_symbols

Message ID 20180727172600.15994-3-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey July 27, 2018, 5:25 p.m. UTC
  -fsanitize=address pointed out a use-after free in
objfile_register_static_link.  The bug turned out to be that
reread_symbols does not clear the static_links field; this leaves a
hash table that is filled with freed pointers.

Jan's (now quite old) idea of replacing reread_symbols with a simple
delete/new still seems good to me, and it's worth noting that it would
have avoided this bug.

gdb/ChangeLog
2018-07-27  Tom Tromey  <tom@tromey.com>

	* symfile.c (reread_symbols): Clear "static_links".
---
 gdb/ChangeLog | 4 ++++
 gdb/symfile.c | 1 +
 2 files changed, 5 insertions(+)
  

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 20697d9dca2..1443c465cc8 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2506,6 +2506,7 @@  reread_symbols (void)
 	  objfile->psymtabs_addrmap = NULL;
 	  objfile->free_psymtabs = NULL;
 	  objfile->template_symbols = NULL;
+	  objfile->static_links = NULL;
 
 	  /* obstack_init also initializes the obstack so it is
 	     empty.  We could use obstack_specify_allocation but