Commit: Check for existence of __gnu_lto_slim symbol name

Nick Clifton nickc@redhat.com
Tue Oct 19 15:01:22 GMT 2021


Hi Guys,

  Whilst working on another bug I came across a case where
  _bfd_generic_link_add_one_symbol() could be called for a symbol with
  no name.  This triggered an illegal memory access error in the code
  that checks the symbol name against __gnu_lto_slim, so I am checking
  in the patch below to prevent this from happening again.

  Since I was updating this code, I thought it best to fix the other
  places where we check for __gnu_lto_slim, even if the name should
  never be null.  Just in case...

Cheers
  Nick

bfd/ChangeLog
2021-10-19  Nick Clifton  <nickc@redhat.com>

	* linker.c (_bfd_generic_link_add_one_symbol): Test for a NULL
	name before checking to see if the symbol is __gnu_lto_slim.
	* archive.c (_bfd_compute_and_write_armap): Likewise.

binutils/ChangeLog
2021-10-19  Nick Clifton  <nickc@redhat.com>

	* nm.c (filter_symbols): Test for a NULL name before checking to
	see if the symbol is __gnu_lto_slim.
	* nm.c (filter_symbols): Likewise.

diff --git a/bfd/linker.c b/bfd/linker.c
index f8257ea11b4..3019daea3a5 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1420,6 +1420,7 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
     {
       row = COMMON_ROW;
       if (!bfd_link_relocatable (info)
+	  && name != NULL
 	  && name[0] == '_'
 	  && name[1] == '_'
 	  && strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0)
diff --git a/bfd/archive.c b/bfd/archive.c
index 2ac680ddc17..dc173560130 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -2357,7 +2357,8 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
 			  map = new_map;
 			}
 
-		      if (syms[src_count]->name[0] == '_'
+		      if (syms[src_count]->name != NULL
+			  && syms[src_count]->name[0] == '_'
 			  && syms[src_count]->name[1] == '_'
 			  && strcmp (syms[src_count]->name
 				     + (syms[src_count]->name[2] == '_'),
diff --git a/binutils/nm.c b/binutils/nm.c
index 82ccec6801c..7606956c92a 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -544,7 +544,8 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
       if (sym == NULL)
 	bfd_fatal (bfd_get_filename (abfd));
 
-      if (sym->name[0] == '_'
+      if (sym->name != NULL
+	  && sym->name[0] == '_'
 	  && sym->name[1] == '_'
 	  && strcmp (sym->name + (sym->name[2] == '_'), "__gnu_lto_slim") == 0
 	  && report_plugin_err)
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 75fd89d338b..0e7400fe4cb 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1542,7 +1542,8 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
 	{
 	  char *new_name;
 
-	  if (name[0] == '_'
+	  if (name != NULL
+	      && name[0] == '_'
 	      && name[1] == '_'
 	      && strcmp (name + (name[2] == '_'), "__gnu_lto_slim") == 0)
 	    {



More information about the Binutils mailing list