[PATCH] BFD: Bound BSD archive symbol names with sentinel

Alhuda Khan alhuda@research.digiscrypt.com
Thu Nov 26 06:40:24 GMT 2026


Hi,

While testing BFD with ASan/UBSan I hit an out-of-bounds read in do_slurp_bsd_armap() (bfd/archive.c). A malformed BSD archive can hold a symbol-name offset that is within the string table but whose name has no NUL terminator before the end of the buffer, so reading it as a C string (e.g. in bfd_hash_hash) runs past the allocation.

The COFF and 64-bit armap readers already guard against this by allocating one extra byte and writing a trailing NUL sentinel (do_slurp_coff_armap, _bfd_archive_64_bit_slurp_armap). do_slurp_bsd_armap doesn't, so this patch brings it in line: allocate one extra byte, place a NUL at the end of the string table, and drop the now-redundant per-symbol check.

Tested with ASan/UBSan — the crafted archive no longer trips a sanitizer report and a valid archive still links. check-binutils shows 169 expected passes; the 3 objdump --disassemble failures are pre-existing and unrelated to archive.c (test log attached).

Signed-off-by: Alhuda Khan <alhuda@research.digiscrypt.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-BFD-Bound-BSD-archive-symbol-names-with-sentinel.patch
Type: application/octet-stream
Size: 1576 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261126/b6593636/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: before.log
Type: application/octet-stream
Size: 4086 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261126/b6593636/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: after.log
Type: application/octet-stream
Size: 59 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261126/b6593636/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bsd-no-nul-large.a
Type: application/octet-stream
Size: 4180 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261126/b6593636/attachment-0001.a>


More information about the Binutils mailing list