[PATCH] D121068: [BOLT][NFC] Check section contents before registering it

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 6 01:53:40 PST 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Address fuzzer crash on malformed input:

  BOLT-ERROR: cannot get section contents for .dynsym: The end of the file was unexpectedly encountered.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121068

Files:
  bolt/include/bolt/Rewrite/RewriteInstance.h
  bolt/lib/Rewrite/RewriteInstance.cpp


Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -765,7 +765,8 @@
 
   if (Error E = discoverStorage())
     return E;
-  readSpecialSections();
+  if (Error E = readSpecialSections())
+    return E;
   adjustCommandLineOptions();
   discoverFileObjects();
 
@@ -1540,7 +1541,7 @@
 
 uint64_t RewriteInstance::getLSDAAddress() { return LSDASection->getAddress(); }
 
-void RewriteInstance::readSpecialSections() {
+Error RewriteInstance::readSpecialSections() {
   NamedRegionTimer T("readSpecialSections", "read special sections",
                      TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
 
@@ -1555,6 +1556,8 @@
 
     // Only register sections with names.
     if (!SectionName.empty()) {
+      if (Error E = Section.getContents().takeError())
+        return E;
       BC->registerSection(Section);
       LLVM_DEBUG(
           dbgs() << "BOLT-DEBUG: registering section " << SectionName << " @ 0x"
@@ -1633,6 +1636,7 @@
 
   // Read .dynamic/PT_DYNAMIC.
   readELFDynamic();
+  return Error::success();
 }
 
 void RewriteInstance::adjustCommandLineOptions() {
Index: bolt/include/bolt/Rewrite/RewriteInstance.h
===================================================================
--- bolt/include/bolt/Rewrite/RewriteInstance.h
+++ bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -96,7 +96,7 @@
 
   /// Read info from special sections. E.g. eh_frame and .gcc_except_table
   /// for exception and stack unwinding information.
-  void readSpecialSections();
+  Error readSpecialSections();
 
   /// Adjust supplied command-line options based on input data.
   void adjustCommandLineOptions();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121068.413284.patch
Type: text/x-patch
Size: 1762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220306/f503b6f5/attachment.bin>


More information about the llvm-commits mailing list