Fix segfault in DWARF function table lookup
Fixes a segfault in DWARF processing when an unusual arange is encountered.
This patch addresses a crash found by oss-fuzz in the DWARF debugging information processing. The fuzzer generated an unusual arange with low=0 and high=(bfd_vma)-1, which resulted in best_fit_len being equal to the initial value. This condition, combined with best_fit being NULL, led to a NULL pointer dereference. The fix adds a check for best_fit == NULL to prevent this segfault.
In Details
The lookup_address_in_function_table function in bfd/dwarf2.c searches for the best-matching function DIE for a given address within a DWARF compilation unit's address range list. The best_fit_len is initialized to a large value, and the first valid arange encountered sets best_fit. If an arange with low=0 and high=(bfd_vma)-1 is processed, arange->high - arange->low can equal the initial best_fit_len. If best_fit is still NULL at this point (meaning no previous match was found), the condition arange->high - arange->low == best_fit_len would be true, and the subsequent der…
- oss-fuzz
- A free fuzzing service provided by Google that combines open-source fuzzing infrastructure with Google's infrastructure to help developers find bugs.
- DWARF
- A debugging data format used by many compilers and debuggers to store information about source code variables, types, and code locations.
- arange
- An Address Range Entry in DWARF debugging information, which defines a range of addresses associated with a particular compilation unit or function.
- compilation unit
- A single source file that is compiled by the compiler. In DWARF, a compilation unit contains debugging information for that source file.
- DIE
- Debug Information Entry. A structured record within DWARF data that describes a program entity like a function, variable, or type.
- NULL pointer dereference
- An error that occurs when a program attempts to access memory through a pointer that has a NULL value.
- bfd_vma
- Represents a virtual memory address within the BFD library, typically used to store addresses from object files.