Author: Jason Molenda Date: 2023-08-18T15:34:13-07:00 New Revision: 1a2122e9e9d1d495fdf337a4a9445b61ca56df6f
URL: https://github.com/llvm/llvm-project/commit/1a2122e9e9d1d495fdf337a4a9445b61ca56df6f DIFF: https://github.com/llvm/llvm-project/commit/1a2122e9e9d1d495fdf337a4a9445b61ca56df6f.diff LOG: Align mach exception data before accessing it The mach exception data may not be doubleword aligned when we receive it. We use memcpy to align it later in this method when we save the data, but for printing the value at the top, we need to do the same or ubsan can trigger when LOG_EXCEPTIONS is enabled in debugserver. Differential Revision: https://reviews.llvm.org/D158312 Added: Modified: lldb/tools/debugserver/source/MacOSX/MachException.cpp Removed: ################################################################################ diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.cpp b/lldb/tools/debugserver/source/MacOSX/MachException.cpp index e760a3ef9faae3..eab4cdfc8b775d 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachException.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachException.cpp @@ -95,13 +95,20 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port, 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(); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits