fix: crash in utilityProcess when generating code from strings (#38014)

This commit is contained in:
Robo 2023-04-20 09:27:02 +09:00 committed by GitHub
parent f12e12b341
commit 0240f6664e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 72 additions and 48 deletions

View file

@ -40,6 +40,7 @@
#include "shell/common/logging.h"
#include "shell/common/options_switches.h"
#include "shell/common/platform_util.h"
#include "shell/common/process_util.h"
#include "shell/common/thread_restrictions.h"
#include "shell/renderer/electron_renderer_client.h"
#include "shell/renderer/electron_sandboxed_renderer_client.h"
@ -83,11 +84,6 @@ constexpr base::StringPiece kElectronDisableSandbox("ELECTRON_DISABLE_SANDBOX");
constexpr base::StringPiece kElectronEnableStackDumping(
"ELECTRON_ENABLE_STACK_DUMPING");
bool IsBrowserProcess(base::CommandLine* cmd) {
std::string process_type = cmd->GetSwitchValueASCII(::switches::kProcessType);
return process_type.empty();
}
// Returns true if this subprocess type needs the ResourceBundle initialized
// and resources loaded.
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
@ -250,14 +246,12 @@ absl::optional<int> ElectronMainDelegate::BasicStartupComplete() {
// On Windows the terminal returns immediately, so we add a new line to
// prevent output in the same line as the prompt.
if (IsBrowserProcess(command_line))
if (IsBrowserProcess())
std::wcout << std::endl;
#endif // !BUILDFLAG(IS_WIN)
auto env = base::Environment::Create();
gin_helper::Locker::SetIsBrowserProcess(IsBrowserProcess(command_line));
// Enable convenient stack printing. This is enabled by default in
// non-official builds.
if (env->HasVar(kElectronEnableStackDumping))
@ -290,7 +284,7 @@ absl::optional<int> ElectronMainDelegate::BasicStartupComplete() {
// bugs, but no use in Electron.
base::win::DisableHandleVerifier();
if (IsBrowserProcess(command_line))
if (IsBrowserProcess())
base::win::PinUser32();
#endif
@ -386,7 +380,7 @@ void ElectronMainDelegate::PreSandboxStartup() {
crash_keys::SetPlatformCrashKey();
#endif
if (IsBrowserProcess(command_line)) {
if (IsBrowserProcess()) {
// Only append arguments for browser process.
// Allow file:// URIs to read other file:// URIs by default.