From 34c4e797bbba3bbeb718340c9ca40eca1536d10b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 25 May 2016 14:40:14 +0900 Subject: [PATCH] Truncate the strings passed to google_breakpad::CustomInfoEntry --- .../crash_reporter/crash_reporter_win.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/atom/common/crash_reporter/crash_reporter_win.cc b/atom/common/crash_reporter/crash_reporter_win.cc index 939a02f090c5..4264f6af9db4 100644 --- a/atom/common/crash_reporter/crash_reporter_win.cc +++ b/atom/common/crash_reporter/crash_reporter_win.cc @@ -43,6 +43,10 @@ const MINIDUMP_TYPE kSmallDumpType = static_cast( const wchar_t kWaitEventFormat[] = L"$1CrashServiceWaitEvent"; const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service"; +// Matches breakpad/src/client/windows/common/ipc_protocol.h. +const int kNameMaxLength = 64; +const int kValueMaxLength = 64; + typedef NTSTATUS (WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle, NTSTATUS ExitStatus); char* g_real_terminate_process_stub = NULL; @@ -247,9 +251,18 @@ google_breakpad::CustomClientInfo* CrashReporterWin::GetCustomInfo( for (StringMap::const_iterator iter = upload_parameters_.begin(); iter != upload_parameters_.end(); ++iter) { - custom_info_entries_.push_back(google_breakpad::CustomInfoEntry( - base::UTF8ToWide(iter->first).c_str(), - base::UTF8ToWide(iter->second).c_str())); + // breakpad has hardcoded the length of name/value, and doesn't truncate + // the values itself, so we have to truncate them here otherwise weird + // things may happen. + std::wstring name = base::UTF8ToWide(iter->first); + std::wstring value = base::UTF8ToWide(iter->second); + if (name.length() > kNameMaxLength - 1) + name.resize(kNameMaxLength - 1); + if (value.length() > kValueMaxLength - 1) + value.resize(kValueMaxLength - 1); + + custom_info_entries_.push_back( + google_breakpad::CustomInfoEntry(name.c_str(), value.c_str())); } custom_info_.entries = &custom_info_entries_.front();