Bug 581866

Summary: don't segfault for non-bfd input
Product: [Fedora] Fedora Reporter: Jim Meyering <meyering>
Component: gdbAssignee: Jan Kratochvil <jan.kratochvil>
Status: CLOSED DUPLICATE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 13CC: jan.kratochvil, pmuldoon
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-04-13 16:24:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jim Meyering 2010-04-13 13:00:42 UTC
Description of problem: gdb segfaults (derefs NULL) for non-BFD input

Version-Release number of selected component (if applicable): gdb-7.1-9.fc13.x86_64

How reproducible: every time

Steps to Reproduce:
1. : > k; gdb k
2.
3.
  
Actual results: segfault

Expected results: diagnostic about invalid file

Additional info:

$ : > k; /usr/bin/gdb --args /usr/bin/gdb k
Reading symbols from /usr/bin/gdb...Reading symbols from /usr/lib/debug/usr/bin/gdb.debug...done.
done.
(gdb) r
Starting program: /usr/bin/gdb k
[Thread debugging using libthread_db enabled]
Detaching after fork from child process 9551.
GNU gdb (GDB) Fedora (7.1-9.fc13)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...

Program received signal SIGSEGV, Segmentation fault.
bfd_check_format_matches (abfd=0x0, format=bfd_core, matching=0x0)
    at ../../bfd/format.c:131
131       if (!bfd_read_p (abfd)
(gdb) p abfd
$1 = (bfd *) 0x0
(gdb) bt
#0  bfd_check_format_matches (abfd=0x0, format=bfd_core, matching=0x0)
    at ../../bfd/format.c:131
#1  0x000000000044a9ba in exec_file_attach (filename=0x7fffffffdd6e "k", 
    from_tty=<value optimized out>) at ../../gdb/exec.c:268
#2  0x0000000000448517 in exec_or_core_file_attach (
    filename=<value optimized out>, from_tty=<value optimized out>)
    at ../../gdb/main.c:257
#3  0x0000000000540417 in catch_command_errors (command=<value optimized out>, 
    arg=<value optimized out>, from_tty=<value optimized out>, 
    mask=<value optimized out>) at ../../gdb/exceptions.c:525
#4  0x0000000000449177 in captured_main (data=<value optimized out>)
    at ../../gdb/main.c:888
#5  0x00000000005404ab in catch_errors (func=<value optimized out>, 
    func_args=<value optimized out>, errstring=<value optimized out>, 
    mask=<value optimized out>) at ../../gdb/exceptions.c:510
#6  0x00000000004483b4 in gdb_main (args=0x3) at ../../gdb/main.c:1009
#7  0x0000000000448389 in main (argc=<value optimized out>, 
    argv=<value optimized out>) at ../../gdb/gdb.c:47

Note that this is already fixed "upstream".
Using it, I get what I would have expected:

$ gdb k
"/t/k": not in executable format: File truncated

Comment 1 Jan Kratochvil 2010-04-13 16:24:10 UTC

*** This bug has been marked as a duplicate of bug 581215 ***