From: Vedant Kumar Date: Fri, 8 Dec 2017 01:09:40 +0000 (+0000) Subject: [MachException] Avoid alignment UB, NFC X-Git-Tag: llvmorg-6.0.0-rc1~1593 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9c36859b33b386fbfa9599646de1e2ae01158180;p=platform%2Fupstream%2Fllvm.git [MachException] Avoid alignment UB, NFC Fix alignment UB in some Mach exception-handling logic. This lets us build lldb and debugserver with UBSan in trapping mode, and get further along in the testing process before a trap is encountered. rdar://35923991 llvm-svn: 320127 --- diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.cpp b/lldb/tools/debugserver/source/MacOSX/MachException.cpp index 12479b8b7e87..cc309e47d86b 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachException.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachException.cpp @@ -113,8 +113,7 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port, g_message->task_port = task_port; g_message->thread_port = thread_port; g_message->exc_type = exc_type; - for (mach_msg_type_number_t i=0; iexc_data.push_back(exc_data[i]); + g_message->AppendExceptionData(exc_data, exc_data_count); return KERN_SUCCESS; } else if (!MachTask::IsValid(g_message->task_port)) { // Our original exception port isn't valid anymore check for a SIGTRAP @@ -126,8 +125,7 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port, g_message->task_port = task_port; g_message->thread_port = thread_port; g_message->exc_type = exc_type; - for (mach_msg_type_number_t i=0; iexc_data.push_back(exc_data[i]); + g_message->AppendExceptionData(exc_data, exc_data_count); return KERN_SUCCESS; } } diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.h b/lldb/tools/debugserver/source/MacOSX/MachException.h index a45a41e01f42..e1af12def10a 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachException.h +++ b/lldb/tools/debugserver/source/MacOSX/MachException.h @@ -71,6 +71,15 @@ public: return (exc_type == EXC_BREAKPOINT || ((exc_type == EXC_SOFTWARE) && exc_data[0] == 1)); } + void AppendExceptionData(mach_exception_data_t Data, + mach_msg_type_number_t Count) { + mach_exception_data_type_t Buf; + for (mach_msg_type_number_t i = 0; i < Count; ++i) { + // Perform an unaligned copy. + memcpy(&Buf, Data + i, sizeof(mach_exception_data_type_t)); + exc_data.push_back(Buf); + } + } void Dump() const; void DumpStopReason() const; bool GetStopInfo(struct DNBThreadStopInfo *stop_info) const;