[Lldb-commits] [lldb] 0f98497 - [lldb] [Mach-O corefiles] Sanity check malformed dyld
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 25 21:51:46 PDT 2024
Author: Jason Molenda
Date: 2024-09-25T21:51:38-07:00
New Revision: 0f984976897857a8f4003063be6fa38a733fa624
URL: https://github.com/llvm/llvm-project/commit/0f984976897857a8f4003063be6fa38a733fa624
DIFF: https://github.com/llvm/llvm-project/commit/0f984976897857a8f4003063be6fa38a733fa624.diff
LOG: [lldb] [Mach-O corefiles] Sanity check malformed dyld
lldb scans the corefile for dyld, the dynamic loader, and when it
finds a mach-o header that looks like dyld, it tries to read all
of the load commands and symbol table out of the corefile memory.
If the load comamnds and symbol table are absent or malformed,
it doesn't handle this case and can crash. Back out when we
fail to create a Module from the dyld binary.
rdar://136659551
Added:
Modified:
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index 624848dee6ec33..30242038a5f66f 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -594,7 +594,7 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos(
}
}
-void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
+bool DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
ImageInfo &image_info) {
if (image_info.header.filetype == llvm::MachO::MH_DYLINKER) {
const bool can_create = true;
@@ -605,8 +605,10 @@ void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
target.GetImages().AppendIfNeeded(dyld_sp);
UpdateImageLoadAddress(dyld_sp.get(), image_info);
SetDYLDModule(dyld_sp);
+ return true;
}
}
+ return false;
}
std::optional<lldb_private::Address> DynamicLoaderDarwin::GetStartAddress() {
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
index 3613c4c29b1785..45c693163f8105 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
@@ -208,7 +208,7 @@ class DynamicLoaderDarwin : public lldb_private::DynamicLoader {
UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos);
// if image_info is a dyld binary, call this method
- void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info);
+ bool UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info);
// If image_infos contains / may contain executable image, call this method
// to keep our internal record keeping of the special dyld binary up-to-date.
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index fe0224483b7c21..debd0f6ee83f40 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -259,10 +259,13 @@ bool DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(
ModuleSP dyld_module_sp;
if (ParseLoadCommands(data, m_dyld, &m_dyld.file_spec)) {
if (m_dyld.file_spec) {
- UpdateDYLDImageInfoFromNewImageInfo(m_dyld);
+ if (!UpdateDYLDImageInfoFromNewImageInfo(m_dyld))
+ return false;
}
}
dyld_module_sp = GetDYLDModule();
+ if (!dyld_module_sp)
+ return false;
Target &target = m_process->GetTarget();
More information about the lldb-commits
mailing list