diff options
author | Nick Clifton <nickc@redhat.com> | 2016-12-06 16:53:57 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2016-12-06 16:53:57 +0000 |
commit | 4f3ca05b487e9755018b4c9a053a2e6c35d8a7df (patch) | |
tree | e959ef5fd42c27c1269f2fd67ed6069f546a856c /bfd/elf.c | |
parent | 8b929e420a810afe23d5ba57a98109c74d1d5816 (diff) | |
download | gdb-4f3ca05b487e9755018b4c9a053a2e6c35d8a7df.zip gdb-4f3ca05b487e9755018b4c9a053a2e6c35d8a7df.tar.gz gdb-4f3ca05b487e9755018b4c9a053a2e6c35d8a7df.tar.bz2 |
Fix seg-fault in strip when copying a corrupt binary.
PR binutils/20931
* elf.c (copy_special_section_fields): Check for an invalid
sh_link field before attempting to follow it.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -1346,6 +1346,16 @@ copy_special_section_fields (const bfd *ibfd, in the input bfd. */ if (iheader->sh_link != SHN_UNDEF) { + /* See PR 20931 for a reproducer. */ + if (iheader->sh_link >= elf_numsections (ibfd)) + { + (* _bfd_error_handler) + /* xgettext:c-format */ + (_("%B: Invalid sh_link field (%d) in section number %d"), + ibfd, iheader->sh_link, secnum); + return FALSE; + } + sh_link = find_link (obfd, iheaders[iheader->sh_link], iheader->sh_link); if (sh_link != SHN_UNDEF) { |