mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: narrow HandleTermination and Shutdown to uint32_t, add tests
Signed-off-by: John Kleinschmidt <kleinschmidtorama@gmail.com>
This commit is contained in:
committed by
John Kleinschmidt
parent
e87807dcbf
commit
792b6a40d1
@@ -244,7 +244,7 @@ void UtilityProcessWrapper::OnServiceProcessLaunch(
|
||||
EmitWithoutEvent("spawn");
|
||||
}
|
||||
|
||||
void UtilityProcessWrapper::HandleTermination(uint64_t exit_code) {
|
||||
void UtilityProcessWrapper::HandleTermination(uint32_t exit_code) {
|
||||
// HandleTermination is called from multiple callsites,
|
||||
// we need to ensure we only process it for the first callsite.
|
||||
if (terminated_)
|
||||
@@ -291,7 +291,7 @@ void UtilityProcessWrapper::OnServiceProcessTerminatedNormally(
|
||||
info.GetProcess().Pid() != pid_)
|
||||
return;
|
||||
|
||||
HandleTermination(static_cast<uint32_t>(info.exit_code()));
|
||||
HandleTermination(info.exit_code());
|
||||
}
|
||||
|
||||
void UtilityProcessWrapper::OnServiceProcessCrashed(
|
||||
@@ -300,7 +300,7 @@ void UtilityProcessWrapper::OnServiceProcessCrashed(
|
||||
info.GetProcess().Pid() != pid_)
|
||||
return;
|
||||
|
||||
HandleTermination(static_cast<uint32_t>(info.exit_code()));
|
||||
HandleTermination(info.exit_code());
|
||||
}
|
||||
|
||||
void UtilityProcessWrapper::CloseConnectorPort() {
|
||||
@@ -312,7 +312,7 @@ void UtilityProcessWrapper::CloseConnectorPort() {
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityProcessWrapper::Shutdown(uint64_t exit_code) {
|
||||
void UtilityProcessWrapper::Shutdown(uint32_t exit_code) {
|
||||
node_service_remote_.reset();
|
||||
HandleTermination(exit_code);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class UtilityProcessWrapper final
|
||||
static gin_helper::Handle<UtilityProcessWrapper> Create(gin::Arguments* args);
|
||||
static raw_ptr<UtilityProcessWrapper> FromProcessId(base::ProcessId pid);
|
||||
|
||||
void Shutdown(uint64_t exit_code);
|
||||
void Shutdown(uint32_t exit_code);
|
||||
|
||||
// gin_helper::Wrappable
|
||||
static gin::DeprecatedWrapperInfo kWrapperInfo;
|
||||
@@ -78,7 +78,7 @@ class UtilityProcessWrapper final
|
||||
void OnServiceProcessLaunch(const base::Process& process);
|
||||
void CloseConnectorPort();
|
||||
|
||||
void HandleTermination(uint64_t exit_code);
|
||||
void HandleTermination(uint32_t exit_code);
|
||||
|
||||
void PostMessage(gin::Arguments* args);
|
||||
bool Kill();
|
||||
|
||||
@@ -129,6 +129,22 @@ describe('utilityProcess module', () => {
|
||||
expect(code).to.equal(exitCode);
|
||||
});
|
||||
|
||||
ifit(process.platform === 'win32')('emits correct exit code when high bit is set on Windows', async () => {
|
||||
// NTSTATUS code with high bit set should not be mangled by sign extension.
|
||||
const exitCode = 0xC0000005;
|
||||
const child = utilityProcess.fork(path.join(fixturesPath, 'custom-exit.js'), [`--exitCode=${exitCode}`]);
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(exitCode);
|
||||
});
|
||||
|
||||
ifit(process.platform !== 'win32')('emits correct exit code when child process crashes on posix', async () => {
|
||||
// Crash exit codes should not be sign-extended to large 64-bit values.
|
||||
const child = utilityProcess.fork(path.join(fixturesPath, 'crash.js'));
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.not.equal(0);
|
||||
expect(code).to.be.lessThanOrEqual(0xFFFFFFFF);
|
||||
});
|
||||
|
||||
it('does not run JS after process.exit is called', async () => {
|
||||
const file = path.join(os.tmpdir(), `no-js-after-exit-log-${Math.random()}`);
|
||||
const child = utilityProcess.fork(path.join(fixturesPath, 'no-js-after-exit.js'), [`--testPath=${file}`]);
|
||||
|
||||
Reference in New Issue
Block a user