From f4dbbf5a8d80770bb65b688fa2c3871d05d432c6 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. lint --- lib/child_process.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 74699a16834c30..53a0b2f9349e85 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -459,7 +459,7 @@ function normalizeSpawnArguments(file, args, options) { // Validate detached, if present. if (options.detached != null && typeof options.detached !== 'boolean') { - throw new ERR_INVALID_ARG_TYPE('options.detached', + throw new ERR_INVALID_ARG_TYPE('options.detached', 'boolean', options.detached); } @@ -758,11 +758,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');