Skip to content

Commit 0f98497

Browse files
committed
[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
1 parent bd592b1 commit 0f98497

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos(
594594
}
595595
}
596596

597-
void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
597+
bool DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
598598
ImageInfo &image_info) {
599599
if (image_info.header.filetype == llvm::MachO::MH_DYLINKER) {
600600
const bool can_create = true;
@@ -605,8 +605,10 @@ void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
605605
target.GetImages().AppendIfNeeded(dyld_sp);
606606
UpdateImageLoadAddress(dyld_sp.get(), image_info);
607607
SetDYLDModule(dyld_sp);
608+
return true;
608609
}
609610
}
611+
return false;
610612
}
611613

612614
std::optional<lldb_private::Address> DynamicLoaderDarwin::GetStartAddress() {

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class DynamicLoaderDarwin : public lldb_private::DynamicLoader {
208208
UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos);
209209

210210
// if image_info is a dyld binary, call this method
211-
void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info);
211+
bool UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info);
212212

213213
// If image_infos contains / may contain executable image, call this method
214214
// to keep our internal record keeping of the special dyld binary up-to-date.

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,13 @@ bool DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(
259259
ModuleSP dyld_module_sp;
260260
if (ParseLoadCommands(data, m_dyld, &m_dyld.file_spec)) {
261261
if (m_dyld.file_spec) {
262-
UpdateDYLDImageInfoFromNewImageInfo(m_dyld);
262+
if (!UpdateDYLDImageInfoFromNewImageInfo(m_dyld))
263+
return false;
263264
}
264265
}
265266
dyld_module_sp = GetDYLDModule();
267+
if (!dyld_module_sp)
268+
return false;
266269

267270
Target &target = m_process->GetTarget();
268271

0 commit comments

Comments
 (0)