Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2022-03-08 20:12:19 +0300
committerAmir Ayupov <aaupov@fb.com>2022-03-08 20:13:01 +0300
commitced5472e09b4abe4f8be863592609ee6bbebf8b2 (patch)
treef99df558830e2329bd68f968721e319a841cc7d4 /bolt
parentf4939d56184e68d1302e8896f7ab32c4405ff609 (diff)
[BOLT][NFC] Check section contents before registering it
Address fuzzer crash on malformed input: ``` BOLT-ERROR: cannot get section contents for .dynsym: The end of the file was unexpectedly encountered. ``` Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D121068
Diffstat (limited to 'bolt')
-rw-r--r--bolt/include/bolt/Rewrite/RewriteInstance.h2
-rw-r--r--bolt/lib/Rewrite/RewriteInstance.cpp8
2 files changed, 7 insertions, 3 deletions
diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 63df47c7bf55..43049a4ee372 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -96,7 +96,7 @@ private:
/// 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();
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index d25f1205afdb..8489caa9d90d 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -765,7 +765,8 @@ Error RewriteInstance::run() {
if (Error E = discoverStorage())
return E;
- readSpecialSections();
+ if (Error E = readSpecialSections())
+ return E;
adjustCommandLineOptions();
discoverFileObjects();
@@ -1540,7 +1541,7 @@ ArrayRef<uint8_t> RewriteInstance::getLSDAData() {
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 @@ void RewriteInstance::readSpecialSections() {
// 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 @@ void RewriteInstance::readSpecialSections() {
// Read .dynamic/PT_DYNAMIC.
readELFDynamic();
+ return Error::success();
}
void RewriteInstance::adjustCommandLineOptions() {