From bbc515d115455b54e9e5864983f1d3ee331c2ec7 Mon Sep 17 00:00:00 2001 From: Minsoo Choo Date: Mon, 30 Mar 2026 14:34:43 +0900 Subject: [PATCH] [lldb][FreeBSDKernel] Add missing error checks in DynamicLoader (#189250) Add extra guards in case a call to function fails. For example, the result of `ReadMemory()` cannot be trusted when `error.Fail()` is true, and this change ensures the code executes properly according to the value of the error. Signed-off-by: Minsoo Choo --- .../FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp index 00b1de6aee36..96883a51bd03 100644 --- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp @@ -162,7 +162,8 @@ bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process, *read_error = false; if (process->ReadMemory(addr, &header, sizeof(header), error) != - sizeof(header)) { + sizeof(header) || + error.Fail()) { if (read_error) *read_error = true; return false; @@ -291,7 +292,8 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::ReadMemoryModule( llvm::ELF::Elf64_Ehdr elf_eheader; Status error; if (process->ReadMemory(m_load_address, &elf_eheader, sizeof(elf_eheader), - error) == sizeof(elf_eheader)) + error) == sizeof(elf_eheader) && + error.Success()) size_to_read = sizeof(llvm::ELF::Elf64_Ehdr) + elf_eheader.e_phnum * elf_eheader.e_phentsize; } @@ -358,7 +360,8 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule( if (IsKernel()) { Status error; if (PluginManager::DownloadObjectAndSymbolFile(module_spec, error, - true)) { + true) && + error.Success()) { if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) m_module_sp = std::make_shared(module_spec.GetFileSpec(), target.GetArchitecture());