From 8646f2bce1911dc888d2fbc7fde5d739d4cac232 Mon Sep 17 00:00:00 2001 From: Sergey Markelov Date: Wed, 7 Aug 2024 11:33:36 -0700 Subject: [PATCH] Fix UB in MinidumpWriter::WriteExceptionStream() calling memcpy() It passed null pointer as a second argument to std::memcpy() when crash_exception_info was empty. This exhibited the undefined behavior. --- src/client/linux/minidump_writer/minidump_writer.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/linux/minidump_writer/minidump_writer.cc b/src/client/linux/minidump_writer/minidump_writer.cc index a95dd2548..44a9c2d63 100644 --- a/src/client/linux/minidump_writer/minidump_writer.cc +++ b/src/client/linux/minidump_writer/minidump_writer.cc @@ -772,9 +772,11 @@ class MinidumpWriter { const std::vector crash_exception_info = dumper_->crash_exception_info(); stream->exception_record.number_parameters = crash_exception_info.size(); - memcpy(stream->exception_record.exception_information, - crash_exception_info.data(), - sizeof(uint64_t) * crash_exception_info.size()); + if (!crash_exception_info.empty()) { + memcpy(stream->exception_record.exception_information, + crash_exception_info.data(), + sizeof(uint64_t) * crash_exception_info.size()); + } stream->thread_context = crashing_thread_context_; return true;