]> granicus.if.org Git - llvm/commit
[llvm-objcopy] --add-symbol: fix crash if SHT_SYMTAB does not exist
authorFangrui Song <maskray@google.com>
Thu, 17 Oct 2019 11:21:54 +0000 (11:21 +0000)
committerFangrui Song <maskray@google.com>
Thu, 17 Oct 2019 11:21:54 +0000 (11:21 +0000)
commit327f5f9ccd21e0a08b9957172f9f63cb0ee31e1b
tree09593fcf9ae19fc7749633a034ae8369f3989139
parent8c62cab5538f46719bfef9e485009853af83b282
[llvm-objcopy] --add-symbol: fix crash if SHT_SYMTAB does not exist

Exposed by D69041. If SHT_SYMTAB does not exist, ELFObjcopy.cpp:handleArgs will crash due
to a null pointer dereference.

  for (const NewSymbolInfo &SI : Config.ELF->SymbolsToAdd) {
    ...
    Obj.SymbolTable->addSymbol(

Fix this by creating .symtab and .strtab on demand in ELFBuilder<ELFT>::readSections,
if --add-symbol is specified.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D69093

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375105 91177308-0d34-0410-b5e6-96231b3b80d8
test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test [new file with mode: 0644]
tools/llvm-objcopy/ELF/ELFObjcopy.cpp
tools/llvm-objcopy/ELF/Object.cpp
tools/llvm-objcopy/ELF/Object.h