[PATCH] D122622: [llvm-pdbutil] Fix a crash due to Expected not checked before destruction

Zequan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 16:44:19 PDT 2022


zequanwu created this revision.
zequanwu added reviewers: rnk, aganea.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122622

Files:
  llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp


Index: llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
===================================================================
--- llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
+++ llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
@@ -531,10 +531,10 @@
   return std::make_pair(std::move(Stream), Headers);
 }
 
-static std::vector<std::string> getSectionNames(PDBFile &File) {
+static Expected<std::vector<std::string>> getSectionNames(PDBFile &File) {
   auto ExpectedHeaders = loadSectionHeaders(File, DbgHeaderType::SectionHdr);
   if (!ExpectedHeaders)
-    return {};
+    return ExpectedHeaders.takeError();
 
   std::unique_ptr<MappedBlockStream> Stream;
   ArrayRef<object::coff_section> Headers;
@@ -604,8 +604,10 @@
       [&](uint32_t Modi, const SymbolGroup &Strings) -> Error {
         auto Desc = Modules.getModuleDescriptor(Modi);
         if (opts::dump::DumpSectionContribs) {
-          std::vector<std::string> Sections = getSectionNames(getPdb());
-          dumpSectionContrib(P, Desc.getSectionContrib(), Sections, 0);
+          auto Sections = getSectionNames(getPdb());
+          if (!Sections)
+            return Sections.takeError();
+          dumpSectionContrib(P, Desc.getSectionContrib(), *Sections, 0);
         }
         P.formatLine("Obj: `{0}`: ", Desc.getObjFileName());
         P.formatLine("debug stream: {0}, # files: {1}, has ec info: {2}",
@@ -1959,8 +1961,10 @@
     ArrayRef<std::string> Names;
   };
 
-  std::vector<std::string> Names = getSectionNames(getPdb());
-  Visitor V(P, makeArrayRef(Names));
+  auto Names = getSectionNames(getPdb());
+  if (!Names)
+    return Names.takeError();
+  Visitor V(P, makeArrayRef(*Names));
   Dbi.visitSectionContributions(V);
   return Error::success();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122622.418729.patch
Type: text/x-patch
Size: 1733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220328/474e8f56/attachment.bin>


More information about the llvm-commits mailing list