[Bug debugedit/33819] debugedit crashes when an object file contains 65,280 or more sections

mark at klomp dot org sourceware-bugzilla@sourceware.org
Tue Mar 10 11:08:42 GMT 2026


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

--- Comment #3 from Mark Wielaard <mark at klomp dot org> ---
commit edc0a3dad12dd4ae5598b82000e689e22f12b735
Author: Mark Wielaard <mark@klomp.org>
Date:   Sun Mar 8 02:09:14 2026 +0100

    debugedit: Support files with more than 65280 ELF sections

    debugedit was using e_shnum, e_phnum and e_shstrndx directly from the
    Elf header. Unfortunately these are too small to contain large
    values. Use elf_getshdrnum and elf_getshdrstrndx and store results in
    DSO. Also use gelf_getsymshndx instead of gelf_getsym to get the
    proper section index for relocation symbols.

    This also works around a crash in libelf when trying to update the Elf
    when section zero hasn't been loaded yet.

    Include a wrapper with an alternative implemention for elf_scnshndx,
    which was broken before elfutils 0.193.

    Add testcase that generates approx 65548 sections plus debuginfo and
    check debugedit can rewrite the file paths.

            * configure.ac: Add AC_PROG_CXX.
            * tools/debugedit.c (DSO): Add shnum and shstrndx.
            (scnshndx): New static function wrapper for elf_scnshndx.
            (setup_relbuf): Get xndxdata if shnum >= SHN_LORESERVE.
            Call gelf_getsymshndx.
            (edit_dwarf2): Use DSO shnum and shstrndx.
            (fdopen_dso): Set shnum and shstrndx.
            (handle_build_id): Use DSO phnum.
            (main): Use DSO shnum and shstrndx.
            * tests/data/SOURCES/large.c: New test source file.
            * tests/Makefile.am (EXTRA_DIST): Add large.c.
            * tests/atlocal.in: Set CXX and CXXFLAGS.
            * tests/debugedit.at (DEBUGEDIT_SETUP_LARGE): New m4 define.
            Add debugedit large file test.

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

    Signed-off-by: Mark Wielaard <mark@klomp.org>

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


More information about the Debugedit mailing list