From 8010c831808caa0decd441efe04f4ecf7f8f6581 Mon Sep 17 00:00:00 2001 From: Nitzan Uziely Date: Sun, 7 Feb 2021 01:52:14 +0200 Subject: [PATCH] child_process: fix bad abort signal leak Move abort signal validation to before spawn is executed so that the file is not leaked. PR-URL: https://github.com/nodejs/node/pull/37257 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca --- lib/child_process.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 8c10ce36cc7d74..e9c52eef7e21ba 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -870,11 +870,14 @@ function spawnWithSignal(file, args, options) { const opts = options && typeof options === 'object' && ('signal' in options) ? { ...options, signal: undefined } : options; - const child = spawn(file, args, opts); - if (options && options.signal) { + if (options?.signal) { // Validate signal, if present validateAbortSignal(options.signal, 'options.signal'); + } + const child = spawn(file, args, opts); + + if (options && options.signal) { function kill() { if (child._handle) { child._handle.kill(options.killSignal || 'SIGTERM');