public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] Check objfile->sf in ada-lang.c
@ 2021-03-02 19:06 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2021-03-02 19:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Most places in gdb that reference objfile->sf also check that it is
not null.  It is valid for it to be null, because find_sym_fns can
return null for some kinds of object file.  However, it's rare to
encounter this scenario with Ada code.  I only encountered it when
looking at a fork of gdb that, I believe, makes its own objfiles
without setting 'sf'.

This patch changes ada-lang.c to check this field before using it.
This avoids any potential crash here.  There's no test case because
I'm not even sure this is possible to trip over with an unmodified
gdb.

There are some other unchecked uses in gdb, but at a quick glance they
all seem to be involved with symbol reading, which of course won't
happen when sf==null.

gdb/ChangeLog
2021-03-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (add_nonlocal_symbols): Handle case where objfile->sf
	is null.
---
 gdb/ChangeLog  |  5 +++++
 gdb/ada-lang.c | 16 +++++++++-------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 419347f776d..91a2a5ce1df 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5629,10 +5629,11 @@ add_nonlocal_symbols (struct obstack *obstackp,
     {
       data.objfile = objfile;
 
-      objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
-					     domain, global, callback,
-					     (is_wild_match
-					      ? NULL : compare_names));
+      if (objfile->sf != nullptr)
+	objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
+					       domain, global, callback,
+					       (is_wild_match
+						? NULL : compare_names));
 
       for (compunit_symtab *cu : objfile->compunits ())
 	{
@@ -5654,9 +5655,10 @@ add_nonlocal_symbols (struct obstack *obstackp,
       for (objfile *objfile : current_program_space->objfiles ())
 	{
 	  data.objfile = objfile;
-	  objfile->sf->qf->map_matching_symbols (objfile, name1,
-						 domain, global, callback,
-						 compare_names);
+	  if (objfile->sf != nullptr)
+	    objfile->sf->qf->map_matching_symbols (objfile, name1,
+						   domain, global, callback,
+						   compare_names);
 	}
     }      	
 }
-- 
2.26.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-02 19:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 19:06 [pushed] Check objfile->sf in ada-lang.c Tom Tromey

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).