fix: crashReporter incompatible with sandbox on Linux (#23265)

This commit is contained in:
Jeremy Apthorp 2020-05-07 13:31:26 -07:00 committed by GitHub
parent fc434f136b
commit 06bf0d08dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 2235 additions and 2404 deletions

View file

@ -4,33 +4,43 @@
#include "shell/app/node_main.h"
#include <map>
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/crash/core/app/crashpad.h"
#include "content/public/common/content_switches.h"
#include "electron/electron_version.h"
#include "gin/array_buffer.h"
#include "gin/public/isolate_holder.h"
#include "gin/v8_initializer.h"
#include "shell/app/electron_crash_reporter_client.h"
#include "shell/app/uv_task_runner.h"
#include "shell/browser/api/electron_api_crash_reporter.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/node_debugger.h"
#include "shell/common/api/electron_bindings.h"
#include "shell/common/crash_reporter/crash_reporter.h"
#include "shell/common/crash_keys.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_bindings.h"
#include "shell/common/node_includes.h"
#if defined(_WIN64)
#include "shell/common/crash_reporter/crash_reporter_win.h"
#if defined(OS_LINUX)
#include "components/crash/core/app/breakpad_linux.h"
#endif
#if defined(OS_WIN)
#include "chrome/child/v8_crashpad_support_win.h"
#endif
namespace {
@ -78,19 +88,64 @@ void SetNodeCliFlags() {
namespace electron {
#if !defined(OS_LINUX)
void AddExtraParameter(const std::string& key, const std::string& value) {
crash_reporter::CrashReporter::GetInstance()->AddExtraParameter(key, value);
}
#if defined(OS_LINUX)
void CrashReporterStart(gin_helper::Dictionary options) {
std::string submit_url;
bool upload_to_server = true;
bool ignore_system_crash_handler = false;
bool rate_limit = false;
bool compress = false;
std::map<std::string, std::string> global_extra;
std::map<std::string, std::string> extra;
options.Get("submitURL", &submit_url);
options.Get("uploadToServer", &upload_to_server);
options.Get("ignoreSystemCrashHandler", &ignore_system_crash_handler);
options.Get("rateLimit", &rate_limit);
options.Get("compress", &compress);
options.Get("extra", &extra);
options.Get("globalExtra", &global_extra);
void RemoveExtraParameter(const std::string& key) {
crash_reporter::CrashReporter::GetInstance()->RemoveExtraParameter(key);
std::string product_name;
if (options.Get("productName", &product_name))
global_extra["_productName"] = product_name;
std::string company_name;
if (options.Get("companyName", &company_name))
global_extra["_companyName"] = company_name;
api::crash_reporter::Start(submit_url, upload_to_server,
ignore_system_crash_handler, rate_limit, compress,
global_extra, extra, true);
}
#endif
v8::Local<v8::Value> GetParameters(v8::Isolate* isolate) {
std::map<std::string, std::string> keys;
#if !defined(MAS_BUILD)
electron::crash_keys::GetCrashKeys(&keys);
#endif
return gin::ConvertToV8(isolate, keys);
}
int NodeMain(int argc, char* argv[]) {
base::CommandLine::Init(argc, argv);
#if defined(OS_WIN)
v8_crashpad_support::SetUp();
#endif
#if !defined(MAS_BUILD)
ElectronCrashReporterClient::Create();
#endif
#if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(MAS_BUILD))
crash_reporter::InitializeCrashpad(false, "node");
#endif
#if !defined(MAS_BUILD)
crash_keys::SetCrashKeysFromCommandLine(
*base::CommandLine::ForCurrentProcess());
crash_keys::SetPlatformCrashKey();
#endif
int exit_code = 1;
{
// Feed gin::PerIsolateData with a task runner.
@ -104,10 +159,6 @@ int NodeMain(int argc, char* argv[]) {
feature_list->InitializeFromCommandLine("", "");
base::FeatureList::SetInstance(std::move(feature_list));
#if defined(_WIN64)
crash_reporter::CrashReporterWin::SetUnhandledExceptionFilter();
#endif
// We do not want to double-set the error level and promise rejection
// callback.
node::g_standalone_mode = false;
@ -159,16 +210,18 @@ int NodeMain(int argc, char* argv[]) {
#endif
process.SetMethod("crash", &ElectronBindings::Crash);
// Setup process.crashReporter.start in child node processes
// Setup process.crashReporter in child node processes
gin_helper::Dictionary reporter = gin::Dictionary::CreateEmpty(isolate);
reporter.SetMethod("start",
&crash_reporter::CrashReporter::StartInstance);
#if !defined(OS_LINUX)
reporter.SetMethod("addExtraParameter", &AddExtraParameter);
reporter.SetMethod("removeExtraParameter", &RemoveExtraParameter);
#if defined(OS_LINUX)
reporter.SetMethod("start", &CrashReporterStart);
#endif
reporter.SetMethod("getParameters", &GetParameters);
reporter.SetMethod("addExtraParameter",
&electron::crash_keys::SetCrashKey);
reporter.SetMethod("removeExtraParameter",
&electron::crash_keys::ClearCrashKey);
process.Set("crashReporter", reporter);
gin_helper::Dictionary versions;