BFD: Fix buffer overflow in nds32_elf_lo12_reloc.
A buffer overflow was fixed in the `nds32_elf_lo12_reloc` function by adding a sanity check on the relocation offset.
A potential buffer overflow in the nds32_elf_lo12_reloc function was fixed. The function reads the lo reloc word when processing stashed hi relocs; a sanity check was added to ensure the relocation offset is valid before accessing memory. The code was also updated to use OCTETS_PER_BYTE instead of bfd_octets_per_byte throughout the file.
In Details
The commit addresses a buffer overflow vulnerability in nds32_elf_lo12_reloc within bfd/elf32-nds32.c. The function now includes a sanity check on the relocation offset using bfd_reloc_offset_in_range to prevent out-of-bounds memory access when processing stashed hi relocs. The code also replaces bfd_octets_per_byte with OCTETS_PER_BYTE.
For Context
The Binary File Descriptor (BFD) library is used to handle object files. Relocations are adjustments to addresses within the object file. The nds32_elf_lo12_reloc function handles specific relocation types for the NDS32 architecture. This commit fixes a potential buffer overflow by adding a sanity check on the relocation offset, ensuring that the function does not read or write to invalid memory locations.