[PATCH] D34752: [LLD][ELF] Fix nullptr dereference when creating an error message.

Sean Eveson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 07:23:36 PDT 2017


seaneveson updated this revision to Diff 104642.
seaneveson added a comment.

Changed to early return as requested.

I haven't been able to find a way to test this, as the crash only occurs for errors in internal sections and I can't find a good way to force one. Do you have any ideas?

Thanks for the review.


https://reviews.llvm.org/D34752

Files:
  ELF/InputSection.cpp


Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -276,7 +276,9 @@
 template <class ELFT> std::string InputSectionBase::getObjMsg(uint64_t Off) {
   // Synthetic sections don't have input files.
   elf::ObjectFile<ELFT> *File = getFile<ELFT>();
-  std::string Filename = File ? File->getName() : "(internal)";
+  if (!File)
+    return ("(internal):" + Name + "+0x" + utohexstr(Off) + ")").str();
+  std::string Filename = File->getName();
 
   std::string Archive;
   if (!File->ArchiveName.empty())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34752.104642.patch
Type: text/x-patch
Size: 610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170629/5ec49d0b/attachment.bin>


More information about the llvm-commits mailing list