Bug 3609 - `objcopy --only-keep-debug` segfaults in current cvs
Summary: `objcopy --only-keep-debug` segfaults in current cvs
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-29 01:23 UTC by Mike Frysinger
Modified: 2006-12-01 16:47 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build:
Last reconfirmed:


Attachments
Do not use the first_section pointer if it is null. (400 bytes, patch)
2006-12-01 12:28 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Frysinger 2006-11-29 01:23:24 UTC
noticed after upgrading to 2.17.50.0.7 (the 2.17.50.0.6 and older work fine):

$ mkdir build
$ cd build
$ CFLAGS='-pipe -O0 -g' ../configure
$ make all-binutils

$ ./binutils/objcopy --only-keep-debug ./binutils/objcopy ./binutils/objcopy.out
Segmentation fault

$ gdb --args ./binutils/objcopy --only-keep-debug ./binutils/objcopy
./binutils/objcopy.out
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r
Starting program: /usr/local/src/gnu/sourceware/build/binutils/objcopy
--only-keep-debug ./binutils/objcopy ./binutils/objcopy.out

Program received signal SIGSEGV, Segmentation fault.
0x0000000000462f5f in rewrite_elf_program_header (ibfd=0x60fbd0, obfd=0x610d40)
at ../../bfd/elf.c:5433
5433          if (first_section->output_section != NULL)
(gdb) bt
#0  0x0000000000462f5f in rewrite_elf_program_header (ibfd=0x60fbd0,
obfd=0x610d40) at ../../bfd/elf.c:5433
#1  0x0000000000464cad in copy_private_bfd_data (ibfd=0x60fbd0, obfd=0x610d40)
at ../../bfd/elf.c:5952
#2  0x000000000046508e in _bfd_elf_copy_private_header_data (ibfd=0x60fbd0,
obfd=0x610d40)
    at ../../bfd/elf.c:6069
#3  0x000000000040579d in setup_bfd_headers (ibfd=0x60fbd0, obfd=0x610d40) at
../../binutils/objcopy.c:2130
#4  0x00000000004040f6 in copy_object (ibfd=0x60fbd0, obfd=0x610d40) at
../../binutils/objcopy.c:1389
#5  0x000000000040551a in copy_file (input_filename=0x7a0570f68042
"./binutils/objcopy", 
    output_filename=0x7a0570f68055 "./binutils/objcopy.out", input_target=0x0, 
    output_target=0x4de188 "elf64-x86-64") at ../../binutils/objcopy.c:2019
#6  0x0000000000407d16 in copy_main (argc=4, argv=0x7a0570f67cd8) at
../../binutils/objcopy.c:3348
#7  0x0000000000407fef in main (argc=4, argv=0x7a0570f67cd8) at
../../binutils/objcopy.c:3438
(gdb)
Comment 1 Nick Clifton 2006-12-01 12:28:53 UTC
Created attachment 1445 [details]
 Do not use the first_section pointer if it is null.
Comment 2 Nick Clifton 2006-12-01 12:29:37 UTC
Hi Mike,

  A simple case of a pointer being used when it was NULL.  I have applied the
uploaded patch to fix this.

Cheers
  Nick
Comment 3 Nick Clifton 2006-12-01 12:30:27 UTC
Hi Mike,

  A simple case of a pointer being used when it was NULL.  I have applied the
uploaded patch to fix this.

Cheers
  Nick

bfd/ChangeLog
2006-12-01  Nick Clifton  <nickc@redhat.com>

	PR 3609
	* elf.c (rewrite_elf_program_header): Do not use the first_section
	pointer if it is null.
Comment 4 H.J. Lu 2006-12-01 15:52:44 UTC
The fix is incorrect. The correct patch is posted at

http://sourceware.org/ml/binutils/2006-12/msg00011.html
Comment 5 H.J. Lu 2006-12-01 16:47:43 UTC
Fixed.