Skip to content

Commit 1a2122e

Browse files
committed
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
1 parent ef70f5c commit 1a2122e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,20 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port,
9595
mach_exception_data_t exc_data,
9696
mach_msg_type_number_t exc_data_count) {
9797
if (DNBLogCheckLogBit(LOG_EXCEPTIONS)) {
98+
std::vector<uint64_t> exc_datas;
99+
uint64_t tmp;
100+
for (unsigned i = 0; i < exc_data_count; ++i) {
101+
// Perform an unaligned copy.
102+
memcpy(&tmp, &exc_data[i], sizeof(uint64_t));
103+
exc_datas.push_back(tmp);
104+
}
98105
DNBLogThreaded("::%s ( exc_port = 0x%4.4x, thd_port = 0x%4.4x, tsk_port = "
99106
"0x%4.4x, exc_type = %d ( %s ), exc_data[%d] = { 0x%llx, "
100107
"0x%llx })",
101108
__FUNCTION__, exc_port, thread_port, task_port, exc_type,
102109
MachException::Name(exc_type), exc_data_count,
103-
(uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
104-
(uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
110+
(uint64_t)(exc_data_count > 0 ? exc_datas[0] : 0xBADDBADD),
111+
(uint64_t)(exc_data_count > 1 ? exc_datas[1] : 0xBADDBADD));
105112
}
106113
g_message->exc_type = 0;
107114
g_message->exc_data.clear();

0 commit comments

Comments
 (0)