Skip to content

Commit

Permalink
child_process: fix bad abort signal leak
Browse files Browse the repository at this point in the history
Move abort signal validation to before spawn is executed
so that the file is not leaked.

lint
  • Loading branch information
Nitzan Uziely committed Feb 7, 2021
1 parent d6e9446 commit f4dbbf5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/child_process.js
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit f4dbbf5

Please sign in to comment.