BFD validates COFF and XCOFF symbol tables before the linker walks them
The COFF and XCOFF linkers now reject symbols whose auxiliary-entry counts run past the table, closing heap overruns on malformed objects.
The COFF and XCOFF linker passes step through the symbol table by 1 + n_numaux entries per symbol, and they advance parallel arrays (sym_hashes, sym_indices, csect_cache, debug_index) in step. A symbol that claims more auxiliary entries than remain in the table pushed those cursors past their buffers. In xcoff_link_input_bfd this caused heap writes into flinfo.sym_indices. Earlier fixes, including the PR 17512 check, only covered coff_get_normalized_symtab and xcoff_link_add_symbols. The XCOFF linker never calls coff_get_normalized_symtab, and the generic COFF linker paths read raw external symbols, so neither was covered. The patch adds direct validation in coffgen.c, cofflink.c and xcofflink.c, plus a new ld-powerpc XCOFF test. Anyone linking untrusted COFF or XCOFF objects gets a clean error instead of heap corruption.
In Details
PR 17512's aux-entry bounds check lives in coff_get_normalized_symtab (coffgen.c). The XCOFF linker reads obj_coff_external_syms directly and never calls it. The generic cofflink.c passes also walk raw externals without canonicalizing them. Hence xcoff_link_input_bfd and the cofflink.c loops, which advance per-symbol arrays by 1 + n_numaux, needed their own validation.
- n_numaux
- A field in a COFF symbol entry giving how many auxiliary symbol records follow it. Each auxiliary record occupies a slot in the symbol table. A corrupt value makes a table walker run past the end.
- auxiliary entry
- An extra fixed-size record that follows a COFF symbol and carries data such as section lengths or function info. Walking the table means skipping them.
- XCOFF
- The extended COFF object format used on AIX and PowerPC. BFD handles it in xcofflink.c with its own link logic.
- coff_get_normalized_symtab
- A BFD function that converts raw on-disk COFF symbols into internal form. It includes the PR 17512 auxiliary-entry bounds check. The XCOFF linker bypasses it.
- sym_indices
- A linker-side array holding the output symbol index for each input symbol. It is sized from obj_raw_syment_count and must advance in step with the symbol walk.
- csect_cache
- An XCOFF linker array mapping symbols to their csect (control section) data. It is walked in parallel with the symbol table.