Segfault in _bfd_delete_bfd with USE_MMAP

Message ID ZhcqHC/oBKmjMMPy@squeak.grove.modra.org
State New
Headers
Series Segfault in _bfd_delete_bfd with USE_MMAP |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 warning Patch is already merged

Commit Message

Alan Modra April 11, 2024, 12:09 a.m. UTC
  Any of the calls to _bfd_delete_bfd in bfd_fopen will hit this.

	* opncls.c (_bfd_delete_bfd): Check for non-NULL xvec before
	accessing flavour.
  

Patch

diff --git a/bfd/opncls.c b/bfd/opncls.c
index 2f8a3a6c919..bc76696dfdb 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -164,7 +164,8 @@  static void
 _bfd_delete_bfd (bfd *abfd)
 {
 #ifdef USE_MMAP
-  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+  if (abfd->xvec
+      && abfd->xvec->flavour == bfd_target_elf_flavour)
     {
       asection *sec;
       for (sec = abfd->sections; sec != NULL; sec = sec->next)