#1002601 binutils: dwp crashes due to NULL pointer for fseek() in gold::Dwp_output_file::write_new_section()

Package:
binutils
Source:
binutils
Description:
GNU assembler, linker and binary utilities
Submitter:
Nicholas Guriev
Date:
2025-08-29 05:33:03 UTC
Severity:
normal
#1002601#5
Date:
2021-12-25 10:40:00 UTC
From:
To:
Dear Maintainer,

dwp(1), packaging tool from binutils, is crashing for no reason on a
simple input. Could you please figure out what is happening and forward
this bug report to upstream authors if appropriate?

Maybe is it my improper use?


builder@barberry:/tmp/tmp.qHMJOXsPej$ cat hello.c
#include <stdio.h>

int main()
{
  puts("Hello everybody!");
  return 0;
}
builder@barberry:/tmp/tmp.qHMJOXsPej$ gcc -g -gsplit-dwarf -c hello.c
builder@barberry:/tmp/tmp.qHMJOXsPej$ gcc -fuse-ld=gold hello.o -o hello
builder@barberry:/tmp/tmp.qHMJOXsPej$ gdb -silent --args dwp -e hello
Reading symbols from dwp...
Reading symbols from /usr/lib/debug/.build-id/eb/5b878b99fdecf3f81089bd0381a7df492ebdfb.debug...
(gdb) r
Starting program: /usr/bin/dwp -e hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
__GI_fseek (fp=0x0, offset=0, whence=0) at fseek.c:35
35      fseek.c: Нет такого файла или каталога.
(gdb) bt full
#0  __GI_fseek (fp=0x0, offset=0, whence=0) at fseek.c:35
        _IO_acquire_lock_file = 0x0
        result = <optimized out>
#1  0x5657919b in gold::Dwp_output_file::write_new_section (this=this@entry=0xffff7540, section_name=section_name@entry=0x5669c3af ".debug_cu_index", contents=contents@entry=0x56739f20 "\002", len=16, align=8) at ../../gold/dwp.cc:1961
        shndx = <optimized out>
        section = <optimized out>
        file_offset = 0
#2  0x5657a334 in gold::Dwp_output_file::write_index<false> (this=0xffff7540, sect_name=0x5669c3af ".debug_cu_index", index=...) at ../../gold/dwp.cc:2070
        nslots = 0
        nused = <optimized out>
        nrows = <optimized out>
        column_mask = <optimized out>
        ncols = <optimized out>
        ntable = <optimized out>
        index_size = 16
        buf = 0x56739f20 "\002"
        p = <optimized out>
        tbl = {_M_current = <optimized out>}
        __FUNCTION__ = {<optimized out> <repeats 12 times>}
#3  0x56570167 in gold::Dwp_output_file::finalize (this=<optimized out>) at ../../gold/dwp.cc:1874
        buf = <optimized out>
        shstrtab_name = <optimized out>
        sh0_link = <optimized out>
        file_offset = <optimized out>
        shstrtab_len = <optimized out>
        shstrtab_off = <optimized out>
        sh0_size = <optimized out>
        buf = <optimized out>
        file_offset = <optimized out>
        shstrtab_name = <optimized out>
        shstrtab_len = <optimized out>
        shstrtab_off = <optimized out>
        sh0_size = <optimized out>
        sh0_link = <optimized out>
        i = <optimized out>
        sect = <optimized out>
        file_offset = <optimized out>
        len = <optimized out>
        i = <optimized out>
        sect = <optimized out>
#4  main (argc=<optimized out>, argv=<optimized out>) at ../../gold/dwp.cc:2448
        errors = {static max_undefined_error_report = 5, program_name_ = 0xffffd81c "/usr/bin/dwp", lock_ = 0x0, initialize_lock_ = {<gold::Once> = {_vptr.Once = 0x567201a8 <vtable for gold::Initialize_lock+8>, was_run_ = false, was_run_lock_ = 0, once_ = 0x56738ba0}, pplock_ = 0xffff74c4}, error_count_ = 0, warning_count_ = 0, undefined_symbols_ = {_M_h = {<std::__detail::_Hashtable_base<gold::Symbol const*, std::pair<gold::Symbol const* const, int>, std::__detail::_Select1st, std::equal_to<gold::Symbol const*>, std::hash<gold::Symbol const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<false, false, true> >> = {<std::__detail::_Hash_code_base<gold::Symbol const*, std::pair<gold::Symbol const* const, int>, std::__detail::_Select1st, std::hash<gold::Symbol const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, false>> = {<std::__detail::_Hashtable_ebo_helper<1, std::hash<gold::Symbol const*>, true>>
        options = {help_initializer_ = {<gold::options::Struct_special> = {<gold::options::Struct_var> = {_vptr.Struct_var = 0x56721da8 <vtable for gold::General_options::Struct_help+8>}, option = {longname = {_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0xffff7a14 "help"}, _M_string_length = 4, {_M_local_buf = "help", '\000' <repeats 11 times>, _M_allocated_capacity = 1886152040}}, dashes = gold::options::TWO_DASHES, shortname = 0 '\000', default_value = 0x566a25a2 "", helpstring = 0x566a32d4 "Report usage information", helparg = 0x0, optional_arg = false, reader = 0xffff7a08, is_default = false}, parse = (void (gold::General_options::*)(gold::General_options * const, const char *, const char *, gold::Command_line *)) 0x5659d6f0 <gold::General_options::parse_help(char const*, char const*, gold::Command_line*)>}, <No data fields>}, version_initializer_ = {<gold::options::Struct_special> = {<gold::options::Stru
        files = {<std::_Vector_base<gold::Dwo_file_entry, std::allocator<gold::Dwo_file_entry> >> = {_M_impl = {<std::allocator<gold::Dwo_file_entry>> = {<__gnu_cxx::new_allocator<gold::Dwo_file_entry>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<gold::Dwo_file_entry, std::allocator<gold::Dwo_file_entry> >::_Vector_impl_data> = {_M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}, <No data fields>}}, <No data fields>}
        output_filename = {_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0xffff7474 "hello.dwp"}, _M_string_length = 9, {_M_local_buf = "hello.dwp\000\000\000\000\000\000", _M_allocated_capacity = 1819043176}}
        exe_filename = <optimized out>
        verbose = <optimized out>
        verify_only = <optimized out>
        c = <optimized out>
        output_file = {name_ = 0xffff7474 "hello.dwp", machine_ = 0, size_ = 0, big_endian_ = 0, osabi_ = 0, abiversion_ = 0, fd_ = 0x0, next_file_offset_ = 0, shnum_ = 2, sections_ = {<std::_Vector_base<gold::Dwp_output_file::Section, std::allocator<gold::Dwp_output_file::Section> >> = {_M_impl = {<std::allocator<gold::Dwp_output_file::Section>> = {<__gnu_cxx::new_allocator<gold::Dwp_output_file::Section>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<gold::Dwp_output_file::Section, std::allocator<gold::Dwp_output_file::Section> >::_Vector_impl_data> = {_M_start = 0x56739c90, _M_finish = 0x56739cb0, _M_end_of_storage = 0x56739cb0}, <No data fields>}}, <No data fields>}, section_id_map_ = {<std::_Vector_base<unsigned int, std::allocator<unsigned int> >> = {_M_impl = {<std::allocator<unsigned int>> = {<__gnu_cxx::new_allocator<unsigned int>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<unsigned int, std::allocator<unsigned int> >::_Vector_impl_data> = {_M_st
(gdb) c
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) q

Long lines have been truncated.