Skip to content

[lldb][FreeBSDKernel] Add missing error checks in DynamicLoader#189250

Merged
mchoo7 merged 1 commit intollvm:mainfrom
mchoo7:error
Mar 30, 2026
Merged

[lldb][FreeBSDKernel] Add missing error checks in DynamicLoader#189250
mchoo7 merged 1 commit intollvm:mainfrom
mchoo7:error

Conversation

@mchoo7
Copy link
Copy Markdown
Contributor

@mchoo7 mchoo7 commented Mar 29, 2026

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.

@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Mar 29, 2026

@llvm/pr-subscribers-lldb

Author: Minsoo Choo (mchoo7)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/189250.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp (+3-3)
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index 00b1de6aee369..c2329f17b339d 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -162,7 +162,7 @@ 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 +291,7 @@ 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 +358,7 @@ 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>(module_spec.GetFileSpec(),
                                                    target.GetArchitecture());

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 29, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Copy link
Copy Markdown
Contributor

@aokblast aokblast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mchoo7 mchoo7 merged commit bbc515d into llvm:main Mar 30, 2026
10 checks passed
@mchoo7 mchoo7 deleted the error branch March 30, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants