Skip to content

Commit

Permalink
child_process: throw TypeError for batch w/o shell
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Apr 25, 2024
1 parent d5c7ffd commit 30cb2cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/internal/child_process.js
Expand Up @@ -13,6 +13,7 @@ const {
StringPrototypeSlice,
Symbol,
SymbolDispose,
TypeError,
Uint8Array,
} = primordials;

Expand Down Expand Up @@ -71,6 +72,7 @@ const {
UV_ENFILE,
UV_ENOENT,
UV_ENOSYS,
UV_EPERM,
UV_ESRCH,
} = internalBinding('uv');

Expand Down Expand Up @@ -418,7 +420,13 @@ ChildProcess.prototype.spawn = function(options) {

this._handle.close();
this._handle = null;
throw new ErrnoException(err, 'spawn');
if (err === UV_EPERM) {
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('The "shell" option must "true" when ' +
'spawning a batch executable');
} else {
throw new ErrnoException(err, 'spawn');
}
} else {
process.nextTick(onSpawnNT, this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/process_wrap.cc
Expand Up @@ -201,7 +201,7 @@ class ProcessWrap : public HandleWrap {
// are not escaped (and sometimes cannot be unambiguously escaped),
// hence why they are rejected here.
if (IsWindowsBatchFile(options.file))
err = UV_EINVAL;
err = UV_EPERM;

// options.args
Local<Value> argv_v =
Expand Down
2 changes: 1 addition & 1 deletion src/spawn_sync.cc
Expand Up @@ -770,7 +770,7 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
// are not escaped (and sometimes cannot be unambiguously escaped),
// hence why they are rejected here.
if (IsWindowsBatchFile(uv_process_options_.file))
return Just<int>(UV_EINVAL);
return Just<int>(UV_EPERM);

Local<Value> js_args =
js_options->Get(context, env()->args_string()).ToLocalChecked();
Expand Down

0 comments on commit 30cb2cd

Please sign in to comment.