2016-12-12 11:05:29 +01:00
|
|
|
// Copyright 2016 The Chromium Embedded Framework Authors. Portions copyright
|
|
|
|
// 2016 The Chromium Authors. All rights reserved. Use of this source code is
|
|
|
|
// governed by a BSD-style license that can be found in the LICENSE file.
|
2013-11-21 23:43:36 +01:00
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
#include "libcef/common/crash_reporter_client.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2013-11-21 23:43:36 +01:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/strings/string16.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2013-11-21 23:43:36 +01:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2018-02-15 01:12:09 +01:00
|
|
|
#include "components/crash/core/common/crash_key.h"
|
|
|
|
#include "third_party/crashpad/crashpad/client/annotation.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
2017-01-27 01:14:56 +01:00
|
|
|
#include "libcef/common/util_mac.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_POSIX)
|
|
|
|
// Don't use CommandLine, FilePath or PathService on Windows. FilePath has
|
|
|
|
// dependencies outside of kernel32, which is disallowed by chrome_elf.
|
|
|
|
// CommandLine and PathService depend on global state that will not be
|
|
|
|
// initialized at the time the CefCrashReporterClient object is created.
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/environment.h"
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/path_service.h"
|
|
|
|
#include "chrome/common/chrome_paths.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2018-02-15 01:12:09 +01:00
|
|
|
#include "libcef/common/cef_crash_report_utils.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "base/debug/leak_annotations.h"
|
|
|
|
#include "chrome/install_static/install_util.h"
|
|
|
|
#include "components/crash/content/app/crashpad.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
typedef base::string16 PathString;
|
|
|
|
const char kPathSep = '\\';
|
|
|
|
#else
|
|
|
|
typedef std::string PathString;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PathString GetCrashConfigPath() {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Start with the path to the running executable.
|
|
|
|
wchar_t module_path[MAX_PATH];
|
|
|
|
if (GetModuleFileName(nullptr, module_path, MAX_PATH) == 0)
|
|
|
|
return PathString();
|
|
|
|
|
|
|
|
PathString config_path = module_path;
|
|
|
|
|
|
|
|
// Remove the executable file name.
|
|
|
|
PathString::size_type last_backslash =
|
|
|
|
config_path.rfind(kPathSep, config_path.size());
|
|
|
|
if (last_backslash != PathString::npos)
|
|
|
|
config_path.erase(last_backslash + 1);
|
|
|
|
|
|
|
|
config_path += L"crash_reporter.cfg";
|
|
|
|
return config_path;
|
|
|
|
#elif defined(OS_POSIX)
|
|
|
|
base::FilePath config_path;
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
2017-01-27 01:14:56 +01:00
|
|
|
// Start with the path to the main app Resources directory. May be empty if
|
|
|
|
// not running in an app bundle.
|
|
|
|
config_path = util_mac::GetMainResourcesDirectory();
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
2017-01-27 01:14:56 +01:00
|
|
|
if (config_path.empty()) {
|
|
|
|
// Start with the path to the running executable.
|
|
|
|
if (!PathService::Get(base::DIR_EXE, &config_path))
|
|
|
|
return PathString();
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
return config_path.Append(FILE_PATH_LITERAL("crash_reporter.cfg")).value();
|
|
|
|
#endif // defined(OS_POSIX)
|
|
|
|
}
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// On Windows, FAT32 and NTFS both limit filenames to a maximum of 255
|
|
|
|
// characters. On POSIX systems, the typical filename length limit is 255
|
|
|
|
// character units. HFS+'s limit is actually 255 Unicode characters using
|
|
|
|
// Apple's modification of Normalization Form D, but the differences aren't
|
|
|
|
// really worth dealing with here.
|
|
|
|
const unsigned maxFilenameLength = 255;
|
|
|
|
|
|
|
|
const char kInvalidFileChars[] = "<>:\"/\\|?*";
|
|
|
|
|
|
|
|
bool isInvalidFileCharacter(unsigned char c) {
|
|
|
|
if (c < ' ' || c == 0x7F)
|
|
|
|
return true;
|
2017-05-17 11:29:28 +02:00
|
|
|
for (size_t i = 0; i < sizeof(kInvalidFileChars); ++i) {
|
2016-12-12 11:05:29 +01:00
|
|
|
if (c == kInvalidFileChars[i])
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAbsolutePath(const std::string& s) {
|
|
|
|
// Check for local paths (beginning with "c:\") and network paths
|
|
|
|
// (beginning with "\\").
|
|
|
|
return s.length() > 2 &&
|
|
|
|
((isalpha(s[0]) && s[1] == ':' && s[2] == kPathSep) ||
|
|
|
|
(s[0] == kPathSep && s[1] == kPathSep));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string extractAbsolutePathStart(std::string& s) {
|
|
|
|
if (!isAbsolutePath(s))
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
std::string start;
|
|
|
|
if (s[0] == kPathSep) {
|
|
|
|
// Network path.
|
|
|
|
start = s.substr(0, 2);
|
|
|
|
s = s.substr(2);
|
|
|
|
} else {
|
|
|
|
// Local path.
|
|
|
|
start = s.substr(0, 3);
|
|
|
|
s = s.substr(3);
|
|
|
|
}
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string sanitizePathComponentPart(const std::string& s) {
|
|
|
|
if (s.empty())
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
result.reserve(s.length());
|
2017-01-13 21:23:19 +01:00
|
|
|
for (size_t i = 0; i < s.length(); ++i) {
|
|
|
|
if (!isInvalidFileCharacter(s[i]))
|
|
|
|
result.push_back(s[i]);
|
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string sanitizePathComponent(const std::string& s) {
|
|
|
|
std::string name, ext;
|
|
|
|
|
|
|
|
// Separate name and extension, if any.
|
|
|
|
std::string::size_type pos = s.rfind('.');
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
name = s.substr(0, pos);
|
|
|
|
ext = s.substr(pos + 1);
|
|
|
|
} else {
|
|
|
|
name = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove invalid characters.
|
|
|
|
name = sanitizePathComponentPart(name);
|
|
|
|
ext = sanitizePathComponentPart(ext);
|
|
|
|
|
|
|
|
// Remove a ridiculously-long extension.
|
|
|
|
if (ext.length() >= maxFilenameLength)
|
|
|
|
ext = std::string();
|
|
|
|
|
|
|
|
// Truncate an overly-long filename, reserving one character for a dot.
|
|
|
|
std::string::size_type max_name_len = maxFilenameLength - ext.length() - 1;
|
|
|
|
if (name.length() > max_name_len)
|
|
|
|
name = name.substr(0, max_name_len);
|
|
|
|
|
|
|
|
return ext.empty() ? name : name + "." + ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string sanitizePath(const std::string& s) {
|
|
|
|
std::string path = s;
|
|
|
|
|
|
|
|
// Extract the absolute path start component, if any (e.g. "c:\" on Windows).
|
|
|
|
std::string result = extractAbsolutePathStart(path);
|
|
|
|
result.reserve(s.length());
|
|
|
|
|
|
|
|
std::vector<std::string> parts =
|
|
|
|
base::SplitString(path, std::string() + kPathSep, base::KEEP_WHITESPACE,
|
|
|
|
base::SPLIT_WANT_NONEMPTY);
|
|
|
|
for (size_t i = 0; i < parts.size(); ++i) {
|
|
|
|
std::string part = parts[i];
|
|
|
|
if (part != "." && part != "..")
|
|
|
|
part = sanitizePathComponent(part);
|
2017-05-17 11:29:28 +02:00
|
|
|
if (!result.empty() && result[result.length() - 1] != kPathSep)
|
2016-12-12 11:05:29 +01:00
|
|
|
result += kPathSep;
|
|
|
|
result += part;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string joinPath(const std::string& s1, const std::string& s2) {
|
|
|
|
if (s1.empty() && s2.empty())
|
|
|
|
return std::string();
|
|
|
|
if (s1.empty())
|
|
|
|
return s2;
|
|
|
|
if (s2.empty())
|
|
|
|
return s1;
|
|
|
|
|
|
|
|
// Don't try to join absolute paths on Windows.
|
|
|
|
// Skip this check on POSIX where it's more difficult to differentiate.
|
|
|
|
if (isAbsolutePath(s2))
|
|
|
|
return s2;
|
|
|
|
|
|
|
|
std::string result = s1;
|
|
|
|
if (result[result.size() - 1] != kPathSep)
|
|
|
|
result += kPathSep;
|
|
|
|
if (s2[0] == kPathSep)
|
|
|
|
result += s2.substr(1);
|
|
|
|
else
|
|
|
|
result += s2;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will only be non-nullptr in the chrome_elf address space.
|
|
|
|
CefCrashReporterClient* g_crash_reporter_client = nullptr;
|
2017-01-23 18:36:54 +01:00
|
|
|
|
|
|
|
#endif // defined(OS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
const char kKeyMapDelim = ',';
|
|
|
|
|
|
|
|
std::string NormalizeCrashKey(const base::StringPiece& key) {
|
|
|
|
std::string str = key.as_string();
|
|
|
|
std::replace(str.begin(), str.end(), kKeyMapDelim, '-');
|
|
|
|
if (str.length() > crashpad::Annotation::kNameMaxLength) {
|
|
|
|
return str.substr(0, crashpad::Annotation::kNameMaxLength);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
// Export functions from chrome_elf that are required by crash_reporting.cc
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
int __declspec(dllexport) __cdecl SetCrashKeyValueImpl(const char* key,
|
|
|
|
size_t key_size,
|
|
|
|
const char* value,
|
|
|
|
size_t value_size) {
|
|
|
|
if (g_crash_reporter_client) {
|
|
|
|
return g_crash_reporter_client->SetCrashKeyValue(
|
|
|
|
base::StringPiece(key, key_size), base::StringPiece(value, value_size));
|
|
|
|
}
|
|
|
|
return 0;
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
int __declspec(dllexport) __cdecl IsCrashReportingEnabledImpl() {
|
|
|
|
return g_crash_reporter_client &&
|
|
|
|
g_crash_reporter_client->HasCrashConfigFile();
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
// The below functions were deleted from chrome/install_static/install_util.cc
|
|
|
|
// in https://crbug.com/565446#c17.
|
|
|
|
|
|
|
|
constexpr wchar_t kUserDataDirname[] = L"User Data";
|
|
|
|
|
|
|
|
// Populates |result| with the default User Data directory for the current
|
|
|
|
// user.This may be overidden by a command line option. Returns false if all
|
|
|
|
// attempts at locating a User Data directory fail.
|
2017-05-17 11:29:28 +02:00
|
|
|
bool GetDefaultUserDataDirectory(std::wstring* result,
|
|
|
|
const std::wstring& install_sub_directory) {
|
2017-01-23 18:36:54 +01:00
|
|
|
// This environment variable should be set on Windows Vista and later
|
|
|
|
// (https://msdn.microsoft.com/library/windows/desktop/dd378457.aspx).
|
|
|
|
std::wstring user_data_dir =
|
|
|
|
install_static::GetEnvironmentString16(L"LOCALAPPDATA");
|
|
|
|
|
|
|
|
if (user_data_dir.empty()) {
|
|
|
|
// LOCALAPPDATA was not set; fallback to the temporary files path.
|
|
|
|
DWORD size = ::GetTempPath(0, nullptr);
|
|
|
|
if (!size)
|
|
|
|
return false;
|
|
|
|
user_data_dir.resize(size + 1);
|
|
|
|
size = ::GetTempPath(size + 1, &user_data_dir[0]);
|
|
|
|
if (!size || size >= user_data_dir.size())
|
|
|
|
return false;
|
|
|
|
user_data_dir.resize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
result->swap(user_data_dir);
|
|
|
|
if ((*result)[result->length() - 1] != L'\\')
|
|
|
|
result->push_back(L'\\');
|
|
|
|
result->append(install_sub_directory);
|
|
|
|
result->push_back(L'\\');
|
|
|
|
result->append(kUserDataDirname);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populates |crash_dir| with the default crash dump location regardless of
|
|
|
|
// whether DIR_USER_DATA or DIR_CRASH_DUMPS has been overridden.
|
2017-05-17 11:29:28 +02:00
|
|
|
bool GetDefaultCrashDumpLocation(std::wstring* crash_dir,
|
|
|
|
const std::wstring& install_sub_directory) {
|
2017-01-23 18:36:54 +01:00
|
|
|
// In order to be able to start crash handling very early, we do not rely on
|
|
|
|
// chrome's PathService entries (for DIR_CRASH_DUMPS) being available on
|
|
|
|
// Windows. See https://crbug.com/564398.
|
|
|
|
if (!GetDefaultUserDataDirectory(crash_dir, install_sub_directory))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We have to make sure the user data dir exists on first run. See
|
|
|
|
// http://crbug.com/591504.
|
|
|
|
if (!install_static::RecursiveDirectoryCreate(*crash_dir))
|
|
|
|
return false;
|
|
|
|
crash_dir->append(L"\\Crashpad");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif // OS_WIN
|
2013-11-21 23:43:36 +01:00
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
CefCrashReporterClient::CefCrashReporterClient() {}
|
|
|
|
CefCrashReporterClient::~CefCrashReporterClient() {}
|
2013-11-21 23:43:36 +01:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// Be aware that logging is not initialized at the time this method is called.
|
|
|
|
bool CefCrashReporterClient::ReadCrashConfigFile() {
|
|
|
|
if (has_crash_config_file_)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
PathString config_path = GetCrashConfigPath();
|
|
|
|
if (config_path.empty())
|
|
|
|
return false;
|
|
|
|
|
2013-11-21 23:43:36 +01:00
|
|
|
#if defined(OS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
FILE* fp = _wfopen(config_path.c_str(), L"r");
|
|
|
|
#else
|
|
|
|
FILE* fp = fopen(config_path.c_str(), "r");
|
|
|
|
#endif
|
|
|
|
if (!fp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char line[1000];
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
size_t small_index = 0;
|
|
|
|
size_t medium_index = 0;
|
|
|
|
size_t large_index = 0;
|
|
|
|
std::string map_keys;
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
enum section {
|
|
|
|
kNoSection,
|
|
|
|
kConfigSection,
|
|
|
|
kCrashKeysSection,
|
|
|
|
} current_section = kNoSection;
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line) - 1, fp) != NULL) {
|
|
|
|
std::string str = line;
|
|
|
|
base::TrimString(str, base::kWhitespaceASCII, &str);
|
|
|
|
if (str.empty() || str[0] == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (str == "[Config]") {
|
|
|
|
current_section = kConfigSection;
|
|
|
|
continue;
|
|
|
|
} else if (str == "[CrashKeys]") {
|
|
|
|
current_section = kCrashKeysSection;
|
|
|
|
continue;
|
|
|
|
} else if (str[0] == '[') {
|
|
|
|
current_section = kNoSection;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_section == kNoSection)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
size_t div = str.find('=');
|
|
|
|
if (div == std::string::npos)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::string name_str = str.substr(0, div);
|
|
|
|
base::TrimString(name_str, base::kWhitespaceASCII, &name_str);
|
|
|
|
std::string val_str = str.substr(div + 1);
|
|
|
|
base::TrimString(val_str, base::kWhitespaceASCII, &val_str);
|
2017-01-12 17:44:35 +01:00
|
|
|
if (name_str.empty())
|
2016-12-12 11:05:29 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (current_section == kConfigSection) {
|
|
|
|
if (name_str == "ServerURL") {
|
2018-03-28 22:02:11 +02:00
|
|
|
if (val_str.find("http://") == 0 || val_str.find("https://") == 0) {
|
2016-12-12 11:05:29 +01:00
|
|
|
server_url_ = val_str;
|
2018-03-28 22:02:11 +02:00
|
|
|
if (server_url_.rfind('/') <= 8) {
|
|
|
|
// Make sure the URL includes a path component. Otherwise, crash
|
|
|
|
// upload will fail on older Windows versions due to
|
|
|
|
// https://crbug.com/826564.
|
|
|
|
server_url_ += "/";
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 17:44:35 +01:00
|
|
|
} else if (name_str == "ProductName") {
|
|
|
|
product_name_ = val_str;
|
|
|
|
} else if (name_str == "ProductVersion") {
|
|
|
|
product_version_ = val_str;
|
2016-12-12 11:05:29 +01:00
|
|
|
} else if (name_str == "RateLimitEnabled") {
|
|
|
|
rate_limit_ = (base::EqualsCaseInsensitiveASCII(val_str, "true") ||
|
|
|
|
val_str == "1");
|
|
|
|
} else if (name_str == "MaxUploadsPerDay") {
|
|
|
|
if (base::StringToInt(val_str, &max_uploads_)) {
|
|
|
|
if (max_uploads_ < 0)
|
|
|
|
max_uploads_ = 0;
|
|
|
|
}
|
|
|
|
} else if (name_str == "MaxDatabaseSizeInMb") {
|
|
|
|
if (base::StringToInt(val_str, &max_db_size_)) {
|
|
|
|
if (max_db_size_ < 0)
|
|
|
|
max_db_size_ = 0;
|
|
|
|
}
|
|
|
|
} else if (name_str == "MaxDatabaseAgeInDays") {
|
|
|
|
if (base::StringToInt(val_str, &max_db_age_)) {
|
|
|
|
if (max_db_age_ < 0)
|
|
|
|
max_db_age_ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
else if (name_str == "ExternalHandler") {
|
2017-01-12 17:44:35 +01:00
|
|
|
if (!val_str.empty())
|
|
|
|
external_handler_ = sanitizePath(val_str);
|
2016-12-12 11:05:29 +01:00
|
|
|
} else if (name_str == "AppName") {
|
2017-01-23 18:36:54 +01:00
|
|
|
if (!val_str.empty()) {
|
|
|
|
val_str = sanitizePathComponent(val_str);
|
|
|
|
if (!val_str.empty())
|
|
|
|
app_name_ = val_str;
|
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
2017-02-06 20:23:59 +01:00
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
else if (name_str == "BrowserCrashForwardingEnabled") {
|
|
|
|
enable_browser_crash_forwarding_ =
|
|
|
|
(base::EqualsCaseInsensitiveASCII(val_str, "true") ||
|
|
|
|
val_str == "1");
|
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
} else if (current_section == kCrashKeysSection) {
|
2018-02-15 01:12:09 +01:00
|
|
|
// Skip duplicate definitions.
|
|
|
|
if (!crash_keys_.empty() &&
|
|
|
|
crash_keys_.find(name_str) != crash_keys_.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeySize size;
|
|
|
|
size_t index;
|
|
|
|
char group;
|
|
|
|
if (val_str == "small") {
|
|
|
|
size = SMALL_SIZE;
|
|
|
|
index = small_index++;
|
|
|
|
group = 'S';
|
|
|
|
} else if (val_str == "medium") {
|
|
|
|
size = MEDIUM_SIZE;
|
|
|
|
index = medium_index++;
|
|
|
|
group = 'M';
|
|
|
|
} else if (val_str == "large") {
|
|
|
|
size = LARGE_SIZE;
|
|
|
|
index = large_index++;
|
|
|
|
group = 'L';
|
|
|
|
} else {
|
2016-12-12 11:05:29 +01:00
|
|
|
continue;
|
2018-02-15 01:12:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
name_str = NormalizeCrashKey(name_str);
|
|
|
|
crash_keys_.insert(std::make_pair(name_str, std::make_pair(size, index)));
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
const std::string& key =
|
|
|
|
std::string(1, group) + "-" + std::string(1, 'A' + index);
|
|
|
|
if (!map_keys.empty()) {
|
|
|
|
map_keys.append(std::string(1, kKeyMapDelim));
|
|
|
|
}
|
|
|
|
map_keys.append(key + "=" + name_str);
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
if (!map_keys.empty()) {
|
|
|
|
// Split |map_keys| across multiple Annotations if necessary.
|
|
|
|
// Must match the logic in crash_report_utils::FilterParameters.
|
|
|
|
using IDKey =
|
|
|
|
crash_reporter::CrashKeyString<crashpad::Annotation::kValueMaxSize>;
|
|
|
|
static IDKey ids[] = {
|
|
|
|
{"K-A", IDKey::Tag::kArray},
|
|
|
|
{"K-B", IDKey::Tag::kArray},
|
|
|
|
{"K-C", IDKey::Tag::kArray},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure we can fit all possible name/value pairs.
|
|
|
|
static_assert(arraysize(ids) * crashpad::Annotation::kValueMaxSize >=
|
|
|
|
3 * 26 /* sizes (small, medium, large) * slots (A to Z) */
|
|
|
|
* (3 + 2 /* key size ("S-A") + delim size ("=,") */
|
|
|
|
+ crashpad::Annotation::kNameMaxLength),
|
|
|
|
"Not enough storage for key map");
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
for (size_t i = 0; i < arraysize(ids); ++i) {
|
|
|
|
size_t length = std::min(map_keys.size() - offset,
|
|
|
|
crashpad::Annotation::kValueMaxSize);
|
|
|
|
ids[i].Set(base::StringPiece(map_keys.data() + offset, length));
|
|
|
|
offset += length;
|
|
|
|
if (offset >= map_keys.size())
|
|
|
|
break;
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
has_crash_config_file_ = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::HasCrashConfigFile() const {
|
|
|
|
return has_crash_config_file_;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefCrashReporterClient::InitializeCrashReportingForProcess() {
|
|
|
|
if (g_crash_reporter_client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_crash_reporter_client = new CefCrashReporterClient();
|
|
|
|
ANNOTATE_LEAKING_OBJECT_PTR(g_crash_reporter_client);
|
|
|
|
|
|
|
|
if (!g_crash_reporter_client->ReadCrashConfigFile())
|
|
|
|
return;
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
std::wstring process_type = install_static::GetSwitchValueFromCommandLine(
|
|
|
|
::GetCommandLineW(), install_static::kProcessType);
|
2016-12-12 11:05:29 +01:00
|
|
|
if (process_type != install_static::kCrashpadHandler) {
|
|
|
|
crash_reporter::SetCrashReporterClient(g_crash_reporter_client);
|
|
|
|
|
|
|
|
// If |embedded_handler| is true then we launch another instance of the main
|
|
|
|
// executable as the crashpad-handler process.
|
|
|
|
const bool embedded_handler =
|
|
|
|
!g_crash_reporter_client->HasCrashExternalHandler();
|
|
|
|
if (embedded_handler) {
|
|
|
|
crash_reporter::InitializeCrashpadWithEmbeddedHandler(
|
2017-05-31 17:33:30 +02:00
|
|
|
process_type.empty(), install_static::UTF16ToUTF8(process_type),
|
|
|
|
std::string());
|
2016-12-12 11:05:29 +01:00
|
|
|
} else {
|
2017-01-23 18:36:54 +01:00
|
|
|
crash_reporter::InitializeCrashpad(
|
|
|
|
process_type.empty(), install_static::UTF16ToUTF8(process_type));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetAlternativeCrashDumpLocation(
|
|
|
|
base::string16* crash_dir) {
|
|
|
|
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
|
|
|
|
// location to write breakpad crash dumps can be set.
|
|
|
|
*crash_dir =
|
|
|
|
install_static::GetEnvironmentString16(L"BREAKPAD_DUMP_LOCATION");
|
|
|
|
return !crash_dir->empty();
|
|
|
|
}
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
void CefCrashReporterClient::GetProductNameAndVersion(
|
2016-06-21 00:59:23 +02:00
|
|
|
const base::string16& exe_path,
|
2013-11-21 23:43:36 +01:00
|
|
|
base::string16* product_name,
|
|
|
|
base::string16* version,
|
|
|
|
base::string16* special_build,
|
|
|
|
base::string16* channel_name) {
|
2017-01-12 17:44:35 +01:00
|
|
|
*product_name = base::ASCIIToUTF16(product_name_);
|
|
|
|
*version = base::ASCIIToUTF16(product_version_);
|
2013-12-17 23:04:35 +01:00
|
|
|
*special_build = base::string16();
|
|
|
|
*channel_name = base::string16();
|
2013-11-21 23:43:36 +01:00
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
bool CefCrashReporterClient::GetCrashDumpLocation(base::string16* crash_dir) {
|
|
|
|
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
|
|
|
|
// location to write breakpad crash dumps can be set.
|
|
|
|
if (GetAlternativeCrashDumpLocation(crash_dir))
|
|
|
|
return true;
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
return GetDefaultCrashDumpLocation(crash_dir, base::UTF8ToUTF16(app_name_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetCrashMetricsLocation(
|
|
|
|
base::string16* metrics_dir) {
|
2017-01-23 18:36:54 +01:00
|
|
|
return GetDefaultUserDataDirectory(metrics_dir, base::UTF8ToUTF16(app_name_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(OS_POSIX)
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefCrashReporterClient::GetProductNameAndVersion(const char** product_name,
|
|
|
|
const char** version) {
|
2017-01-12 17:44:35 +01:00
|
|
|
*product_name = product_name_.c_str();
|
|
|
|
*version = product_version_.c_str();
|
2013-11-21 23:43:36 +01:00
|
|
|
}
|
|
|
|
|
2017-01-12 17:44:35 +01:00
|
|
|
#if !defined(OS_MACOSX)
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
base::FilePath CefCrashReporterClient::GetReporterLogFilename() {
|
2013-11-21 23:43:36 +01:00
|
|
|
return base::FilePath(FILE_PATH_LITERAL("uploads.log"));
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
bool CefCrashReporterClient::EnableBreakpadForProcess(
|
|
|
|
const std::string& process_type) {
|
|
|
|
return process_type == switches::kRendererProcess ||
|
|
|
|
process_type == switches::kPpapiPluginProcess ||
|
|
|
|
process_type == switches::kZygoteProcess ||
|
|
|
|
process_type == switches::kGpuProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(OS_MACOSX)
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
bool CefCrashReporterClient::GetCrashDumpLocation(base::FilePath* crash_dir) {
|
2016-12-12 11:05:29 +01:00
|
|
|
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
|
|
|
|
// location to write breakpad crash dumps can be set.
|
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
std::string alternate_crash_dump_location;
|
|
|
|
if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) {
|
|
|
|
base::FilePath crash_dumps_dir_path =
|
|
|
|
base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
|
|
|
|
PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path);
|
|
|
|
}
|
|
|
|
return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(OS_POSIX)
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetCollectStatsConsent() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetCollectStatsInSample() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_WIN) || defined(OS_MACOSX)
|
|
|
|
bool CefCrashReporterClient::ReportingIsEnforcedByPolicy(
|
|
|
|
bool* crashpad_enabled) {
|
|
|
|
*crashpad_enabled = true;
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-21 00:59:23 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
bool CefCrashReporterClient::IsRunningUnattended() {
|
|
|
|
// Crash upload will only be enabled with Breakpad on Linux if this method
|
|
|
|
// returns false.
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-21 23:43:36 +01:00
|
|
|
#endif
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
std::string CefCrashReporterClient::GetCrashServerURL() {
|
|
|
|
return server_url_;
|
2016-04-27 22:38:52 +02:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
// See HandlerMain() in third_party/crashpad/crashpad/handler/handler_main.cc
|
|
|
|
// for supported arguments.
|
|
|
|
void CefCrashReporterClient::GetCrashOptionalArguments(
|
|
|
|
std::vector<std::string>* arguments) {
|
|
|
|
if (!rate_limit_)
|
|
|
|
arguments->push_back(std::string("--no-rate-limit"));
|
|
|
|
|
|
|
|
if (max_uploads_ > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
arguments->push_back(std::string("--max-uploads=") +
|
|
|
|
base::IntToString(max_uploads_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max_db_size_ > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
arguments->push_back(std::string("--max-db-size=") +
|
|
|
|
base::IntToString(max_db_size_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max_db_age_ > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
arguments->push_back(std::string("--max-db-age=") +
|
|
|
|
base::IntToString(max_db_age_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
|
|
|
|
base::string16 CefCrashReporterClient::GetCrashExternalHandler(
|
|
|
|
const base::string16& exe_dir) {
|
|
|
|
if (external_handler_.empty())
|
|
|
|
return CrashReporterClient::GetCrashExternalHandler(exe_dir);
|
|
|
|
if (isAbsolutePath(external_handler_))
|
|
|
|
return base::UTF8ToUTF16(external_handler_);
|
|
|
|
return base::UTF8ToWide(
|
|
|
|
joinPath(base::UTF16ToUTF8(exe_dir), external_handler_));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::HasCrashExternalHandler() const {
|
|
|
|
return !external_handler_.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(OS_WIN)
|
2017-02-06 20:23:59 +01:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
bool CefCrashReporterClient::EnableBrowserCrashForwarding() {
|
|
|
|
return enable_browser_crash_forwarding_;
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-15 01:12:09 +01:00
|
|
|
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
CefCrashReporterClient::ParameterMap CefCrashReporterClient::FilterParameters(
|
|
|
|
const ParameterMap& parameters) {
|
|
|
|
return crash_report_utils::FilterParameters(parameters);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// The new Crashpad Annotation API requires that annotations be declared using
|
|
|
|
// static storage. We work around this limitation by defining a fixed amount of
|
|
|
|
// storage for each key size and later substituting the actual key name during
|
|
|
|
// crash dump processing.
|
|
|
|
|
|
|
|
#define IDKEY(name) \
|
|
|
|
{ name, IDKey::Tag::kArray }
|
|
|
|
|
|
|
|
#define IDKEY_ENTRIES(n) \
|
|
|
|
IDKEY(n "-A"), IDKEY(n "-B"), IDKEY(n "-C"), IDKEY(n "-D"), IDKEY(n "-E"), \
|
|
|
|
IDKEY(n "-F"), IDKEY(n "-G"), IDKEY(n "-H"), IDKEY(n "-I"), \
|
|
|
|
IDKEY(n "-J"), IDKEY(n "-K"), IDKEY(n "-L"), IDKEY(n "-M"), \
|
|
|
|
IDKEY(n "-N"), IDKEY(n "-O"), IDKEY(n "-P"), IDKEY(n "-Q"), \
|
|
|
|
IDKEY(n "-R"), IDKEY(n "-S"), IDKEY(n "-T"), IDKEY(n "-U"), \
|
|
|
|
IDKEY(n "-V"), IDKEY(n "-W"), IDKEY(n "-X"), IDKEY(n "-Y"), \
|
|
|
|
IDKEY(n "-Z")
|
|
|
|
|
|
|
|
#define IDKEY_FUNCTION(name, size) \
|
|
|
|
static_assert(size <= crashpad::Annotation::kValueMaxSize, \
|
|
|
|
"Annotation size is too large."); \
|
|
|
|
bool Set##name##Annotation(size_t index, const base::StringPiece& value) { \
|
|
|
|
using IDKey = crash_reporter::CrashKeyString<size>; \
|
|
|
|
static IDKey ids[] = {IDKEY_ENTRIES(#name)}; \
|
|
|
|
if (index < arraysize(ids)) { \
|
|
|
|
if (value.empty()) { \
|
|
|
|
ids[index].Clear(); \
|
|
|
|
} else { \
|
|
|
|
ids[index].Set(value); \
|
|
|
|
} \
|
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
return false; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// The first argument must be kept synchronized with the logic in
|
|
|
|
// CefCrashReporterClient::ReadCrashConfigFile and
|
|
|
|
// crash_report_utils::FilterParameters.
|
|
|
|
IDKEY_FUNCTION(S, 64)
|
|
|
|
IDKEY_FUNCTION(M, 256)
|
|
|
|
IDKEY_FUNCTION(L, 1024)
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::SetCrashKeyValue(const base::StringPiece& key,
|
|
|
|
const base::StringPiece& value) {
|
|
|
|
if (key.empty() || crash_keys_.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
KeyMap::const_iterator it = crash_keys_.find(NormalizeCrashKey(key));
|
|
|
|
if (it == crash_keys_.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const KeySize size = it->second.first;
|
|
|
|
const size_t index = it->second.second;
|
|
|
|
|
|
|
|
base::AutoLock lock_scope(crash_key_lock_);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case SMALL_SIZE:
|
|
|
|
return SetSAnnotation(index, value);
|
|
|
|
case MEDIUM_SIZE:
|
|
|
|
return SetMAnnotation(index, value);
|
|
|
|
case LARGE_SIZE:
|
|
|
|
return SetLAnnotation(index, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|