[llvm] r344268 - [llvm-nm] Fix crash when running with --print-armap on corrupt archives.

Jordan Rupprecht via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 10:55:11 PDT 2018


Author: rupprecht
Date: Thu Oct 11 10:55:11 2018
New Revision: 344268

URL: http://llvm.org/viewvc/llvm-project?rev=344268&view=rev
Log:
[llvm-nm] Fix crash when running with --print-armap on corrupt archives.

error() in llvm-nm intentionally does not return so that the callee can move on to future files/slices. When printing the archive map, this is not currently handled (the caller assumes that error() returns), so processing continues despite there being an error.

Also, change one return to a break, so that symbols can be printed even if the archive map is corrupt.

Modified:
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=344268&r1=344267&r2=344268&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Thu Oct 11 10:55:11 2018
@@ -1755,12 +1755,14 @@ static void dumpSymbolNamesFromFile(std:
         outs() << "Archive map\n";
         for (; I != E; ++I) {
           Expected<Archive::Child> C = I->getMember();
-          if (!C)
+          if (!C) {
             error(C.takeError(), Filename);
+            break;
+          }
           Expected<StringRef> FileNameOrErr = C->getName();
           if (!FileNameOrErr) {
             error(FileNameOrErr.takeError(), Filename);
-            return;
+            break;
           }
           StringRef SymName = I->getName();
           outs() << SymName << " in " << FileNameOrErr.get() << "\n";




More information about the llvm-commits mailing list