[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 <minsoochoo0122@proton.me>
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index 00b1de6..96883a5 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -162,7 +162,8 @@
*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 @@
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 @@
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>(module_spec.GetFileSpec(),
target.GetArchitecture());