From 7bd387a5a6f63c0f3b618131eb993b962548b39b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 13 Feb 2020 12:40:53 +0100 Subject: [PATCH] src: fix spawnSync CHECK when SIGKILL fails We might not have sufficient privileges to signal the child process so don't make assumptions about the return value of `uv_process_kill()`. Example: node -e 'child_process.spawnSync("sudo", ["ls"], { maxBuffer: 1 })' No test because: 1. The test needs to run as root (can't invoke sudo), and 2. The parent needs to drop privileges but can't, because then the child process won't have sufficient privileges. Fixes: https://github.com/nodejs/node/issues/31747 --- src/spawn_sync.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 3b277ad70adb66..611f9c7c03ec48 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -607,8 +607,9 @@ void SyncProcessRunner::Kill() { if (r < 0 && r != UV_ESRCH) { SetError(r); - r = uv_process_kill(&uv_process_, SIGKILL); - CHECK(r >= 0 || r == UV_ESRCH); + // Deliberately ignore the return value, we might not have + // sufficient privileges to signal the child process. + USE(uv_process_kill(&uv_process_, SIGKILL)); } }