Fix lookup_address_in_function_table segfault

Message ID auJ2PxF59Bdag8fA@squeak.grove.modra.org
State New
Headers
Series Fix lookup_address_in_function_table segfault |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Oct. 28, 2026, 10:25 p.m. UTC
  oss-fuzz found a hole in commit b2e68bf063e5 (bfd/dwarf2: break
equal-range function ties by DIE offset).  The fuzzer created an
arange with low=0 and high=(bfd_vma)-1 which of course is ridiculous
but equals the initial (no match yet) best_fit_len.

	* dwarf2.c (lookup_address_in_function_table): Add best_fit
	NULL check.
  

Patch

diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 61473a5034f..084a1c5d8cc 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -3363,6 +3363,7 @@  lookup_address_in_function_table (struct comp_unit *unit,
 	    continue;
 
 	  if (arange->high - arange->low < best_fit_len
+	      || best_fit == NULL
 	      /* Among matches of the same length take the one later in the
 		 DIE stream.  */
 	      || (arange->high - arange->low == best_fit_len