From cf176be8ae1ae96ebb6af4f418f1c8a4e41d2953 Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Fri, 17 Oct 2025 11:11:47 +0200 Subject: [PATCH 1/2] fix(win): dynamically size minidump_path in handler instead of using MAX_PATH --- .../windows/handler/exception_handler.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/client/windows/handler/exception_handler.cc b/src/client/windows/handler/exception_handler.cc index 64b297999..25312b0ce 100644 --- a/src/client/windows/handler/exception_handler.cc +++ b/src/client/windows/handler/exception_handler.cc @@ -1049,14 +1049,23 @@ void ExceptionHandler::UpdateNextID() { next_minidump_id_ = GUIDString::GUIDToWString(&id); next_minidump_id_c_ = next_minidump_id_.c_str(); - wchar_t minidump_path[MAX_PATH]; - swprintf(minidump_path, MAX_PATH, L"%s\\%s.dmp", - dump_path_c_, next_minidump_id_c_); + const size_t dump_path_c_len = wcslen(dump_path_c_); + const size_t next_minidump_id_c_len = wcslen(next_minidump_id_c_); + // 1 for backslash + 4 for ".dmp" + 1 for NUL + const size_t minidump_path_len = + dump_path_c_len + 1 + next_minidump_id_c_len + 4 + 1; + std::vector minidump_path(minidump_path_len); + const int written = + swprintf(minidump_path.data(), minidump_path_len, L"%s\\%s.dmp", + dump_path_c_, next_minidump_id_c_); + if (written < 0 || static_cast(written) >= minidump_path.size()) { + return; + } // remove when VC++7.1 is no longer supported - minidump_path[MAX_PATH - 1] = L'\0'; + minidump_path.back() = L'\0'; - next_minidump_path_ = minidump_path; + next_minidump_path_.assign(minidump_path.data()); next_minidump_path_c_ = next_minidump_path_.c_str(); } From 1223135f72a2dd425b6a87bb8a1c55104cb7fb69 Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Fri, 17 Oct 2025 15:21:21 +0200 Subject: [PATCH 2/2] reset next_minidump_path_[c_] if swprintf fails --- src/client/windows/handler/exception_handler.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client/windows/handler/exception_handler.cc b/src/client/windows/handler/exception_handler.cc index 25312b0ce..6a156e4a9 100644 --- a/src/client/windows/handler/exception_handler.cc +++ b/src/client/windows/handler/exception_handler.cc @@ -1059,6 +1059,10 @@ void ExceptionHandler::UpdateNextID() { swprintf(minidump_path.data(), minidump_path_len, L"%s\\%s.dmp", dump_path_c_, next_minidump_id_c_); if (written < 0 || static_cast(written) >= minidump_path.size()) { + // `swprintf` either encountered an encoding error or truncation. + // Let's reset the `next`-members and exit early to not cause overwriting. + next_minidump_path_.clear(); + next_minidump_path_c_ = nullptr; return; }