mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: correct utility process exit code on Windows (#50387)
* fix: correct utility process exit code on Windows On Windows, process exit codes are 32-bit unsigned integers (DWORD). When passed from Chromium to Electron as a signed int and then implicitly converted to uint64_t, values with the high bit set (e.g., NTSTATUS codes) undergo sign extension, producing incorrect values. Cast the exit code to uint32_t before widening to uint64_t to prevent sign extension and preserve the original Windows exit code. Fixes #49455 Co-authored-by: João Silva <joaomrsilva@tecnico.ulisboa.pt> * fix: narrow HandleTermination and Shutdown to uint32_t, add tests Co-authored-by: João Silva <joaomrsilva@tecnico.ulisboa.pt> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: João Silva <joaomrsilva@tecnico.ulisboa.pt>
This commit is contained in:
@@ -258,7 +258,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_)
|
||||
@@ -326,7 +326,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);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,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;
|
||||
@@ -77,7 +77,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