[Lldb-commits] [lldb] [lldb][windows] fix 4-byte error-code read (PR #197177)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Tue May 12 05:52:41 PDT 2026


https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/197177

Reading `word_size` (8) bytes here would include 4 bytes of stack garbage past the struct and produce bogus error codes.

>From 837a74668a01d126cecf89e8eaf274343f461f89 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 12 May 2026 13:50:39 +0100
Subject: [PATCH] [lldb][windows] fix 4-byte error-code read

---
 lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
index 9e11b66068381..c82841ab029aa 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -398,10 +398,10 @@ uint32_t PlatformWindows::DoLoadImage(Process *process,
   }
 
   if (!token) {
-    // XXX(compnerd) should we use the compiler to get the sizeof(unsigned)?
-    uint64_t error_code =
-        process->ReadUnsignedIntegerFromMemory(injected_result + 2 * word_size + sizeof(unsigned),
-                                               word_size, 0, status);
+    // ErrorCode is a 4-byte `unsigned` field in __lldb_LoadLibraryResult.
+    uint64_t error_code = process->ReadUnsignedIntegerFromMemory(
+        injected_result + 2 * word_size + sizeof(unsigned), sizeof(unsigned), 0,
+        status);
     if (status.Fail()) {
       error = Status::FromErrorStringWithFormat(
           "LoadLibrary error: could not read error status: %s",



More information about the lldb-commits mailing list