https://sourceware.org/bugzilla/show_bug.cgi?id=35097

            Bug ID: 35097
           Summary: GNU ld generic COFF empty symbol table forms a pointer
                    from NULL
           Product: binutils
           Version: 2.48 (HEAD)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: emily.west286 at gmail dot com
  Target Milestone: ---

Created attachment 17327
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17327&action=edit
Test cases and reproduction script

Product: binutils
Component: ld
Version: current master (716b214ad8db)
Host/target: All-target GNU ld (x86-64 and Arm64 PE)

Summary
-------

Setting one COFF NumberOfSymbols field from 2 to 0 makes ld evaluate
NULL + 0 in _bfd_coff_link_input_bfd (bfd/cofflink.c:1592).

Reproduction
------------

1. Extract
`bfd-coff-empty-symbol-table-null-pointer-arithmetic-reproducer.tar.gz`.
2. Run:

       LD_BFD=/path/to/ld-new sh repro.sh

   Without a local build, use the `bfd-repro` image:

       docker run --rm -v "$PWD:/queue:ro" bfd-repro \
        
/queue/attachments/bfd-coff-empty-symbol-table-null-pointer-arithmetic-reproducer.tar.gz

Observed result
---------------

Master 716b214ad8db, Clang ASan+UBSan. x86-64 trigger:

    /opt/bfd/ld-new: inputs/x86_64-trigger.obj: warning: illegal symbol index 1
in relocs
    ../../bfd/cofflink.c:1592:19: runtime error: applying zero offset to null
pointer
    ==11==WARNING: invalid path to external symbolizer!
    ==11==WARNING: Failed to use and restart external symbolizer!
        #0 0x5618783533c3  (/opt/bfd/ld-new+0x1b463c3) (BuildId:
cdf54a78f712fddf693b6a6d40dd2b8a40f19f55)
        #1 0x561878346b9c  (/opt/bfd/ld-new+0x1b39b9c) (BuildId:
cdf54a78f712fddf693b6a6d40dd2b8a40f19f55)
        #2 0x561877c99d37  (/opt/bfd/ld-new+0x148cd37) (BuildId:
cdf54a78f712fddf693b6a6d40dd2b8a40f19f55)
        #3 0x561877c92b81  (/opt/bfd/ld-new+0x1485b81) (BuildId:
cdf54a78f712fddf693b6a6d40dd2b8a40f19f55)
        #4 0x7f0cd112c249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #5 0x7f0cd112c304  (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #6 0x561877b73690  (/opt/bfd/ld-new+0x1366690) (BuildId:
cdf54a78f712fddf693b6a6d40dd2b8a40f19f55)

    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../bfd/cofflink.c:1592:19 in
    Aborted (core dumped)

The Arm64 trigger reports the same runtime error. Both well-formed controls
exit 0 with no diagnostics.

Expected result
---------------

ld should reject the malformed input with a normal diagnostic, not evaluate
NULL + 0.

Validation
----------

* Master 716b214ad8db, all targets, Clang ASan+UBSan: both triggers abort at
cofflink.c:1592:19; both controls exit 0.
* Duplicate check (2026-12-02): no matching Sourceware report found.
* Related: PR 34868 is an empty XCOFF symbol table at a different site.

Suggested fix
-------------

`bfd-coff-empty-symbol-table-null-pointer-arithmetic.patch` computes `esym_end`
only when the external symbol buffer exists, in both places it's used.
Tested on master 716b214ad8db: both triggers now fail with "invalid symbol
index 1 in relocs" and "final link failed", with no sanitizer diagnostic, and
both controls still exit 0. Test image: `patch.Dockerfile`, built with
`--build-arg PATCH=bfd-coff-empty-symbol-table-null-pointer-arithmetic.patch`.

Scope
-----

Robustness issue. No invalid write across a security boundary is established.

Attachment
----------

- `bfd-coff-empty-symbol-table-null-pointer-arithmetic-reproducer.tar.gz`
- `bfd-coff-empty-symbol-table-null-pointer-arithmetic.patch`
- `patch.Dockerfile`

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to