[ELF] - Fixed crash on invalid input.

I took the input from https://llvm.org/bugs/show_bug.cgi?id=30540, it was
"id_000000,sig_11,src_000000,op_flip1,pos_98"

File contains invalid symbol name offset (too large) and lld just crashes,
patch fixes the issue.

Differential revision: https://reviews.llvm.org/D24970

llvm-svn: 282709
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 9ac5135..7774507 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -380,7 +380,7 @@
   if (!Out<ELFT>::SymTab)
     return;
   for (elf::ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
-    const char *StrTab = F->getStringTable().data();
+    StringRef StrTab = F->getStringTable();
     for (SymbolBody *B : F->getLocalSymbols()) {
       auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
       // No reason to keep local undefined symbol in symtab.
@@ -388,7 +388,9 @@
         continue;
       if (!includeInSymtab<ELFT>(*B))
         continue;
-      StringRef SymName(StrTab + B->getNameOffset());
+      if (B->getNameOffset() >= StrTab.size())
+        fatal(getFilename(F) + ": invalid symbol name offset");
+      StringRef SymName(StrTab.data() + B->getNameOffset());
       InputSectionBase<ELFT> *Sec = DR->Section;
       if (!shouldKeepInSymtab<ELFT>(Sec, SymName, *B))
         continue;