[Lldb-commits] [PATCH] D158312: [debugserver] align received mach exception data before accessing it as array of uint64_t's, fix UB sanitizer failure

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 18 15:34:57 PDT 2023


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1a2122e9e9d1: Align mach exception data before accessing it (authored by jasonmolenda).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158312/new/

https://reviews.llvm.org/D158312

Files:
  lldb/tools/debugserver/source/MacOSX/MachException.cpp


Index: lldb/tools/debugserver/source/MacOSX/MachException.cpp
===================================================================
--- lldb/tools/debugserver/source/MacOSX/MachException.cpp
+++ lldb/tools/debugserver/source/MacOSX/MachException.cpp
@@ -95,13 +95,20 @@
                            mach_exception_data_t exc_data,
                            mach_msg_type_number_t exc_data_count) {
   if (DNBLogCheckLogBit(LOG_EXCEPTIONS)) {
+    std::vector<uint64_t> exc_datas;
+    uint64_t tmp;
+    for (unsigned i = 0; i < exc_data_count; ++i) {
+      // Perform an unaligned copy.
+      memcpy(&tmp, &exc_data[i], sizeof(uint64_t));
+      exc_datas.push_back(tmp);
+    }
     DNBLogThreaded("::%s ( exc_port = 0x%4.4x, thd_port = 0x%4.4x, tsk_port = "
                    "0x%4.4x, exc_type = %d ( %s ), exc_data[%d] = { 0x%llx, "
                    "0x%llx })",
                    __FUNCTION__, exc_port, thread_port, task_port, exc_type,
                    MachException::Name(exc_type), exc_data_count,
-                   (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
-                   (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
+                   (uint64_t)(exc_data_count > 0 ? exc_datas[0] : 0xBADDBADD),
+                   (uint64_t)(exc_data_count > 1 ? exc_datas[1] : 0xBADDBADD));
   }
   g_message->exc_type = 0;
   g_message->exc_data.clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158312.551661.patch
Type: text/x-patch
Size: 1404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230818/83afb75f/attachment.bin>


More information about the lldb-commits mailing list