shell: exec encoding is utf8 by default and no shell

explicitly mark calls that require the shell
This commit is contained in:
Girish Ramakrishnan
2024-02-21 17:16:33 +01:00
parent 23cac99fe9
commit 14c9260ab0
14 changed files with 54 additions and 51 deletions
+8 -4
View File
@@ -19,7 +19,7 @@ exports = module.exports = {
const SUDO = '/usr/bin/sudo';
// default encoding utf8, shell, handles input. full command
// default encoding utf8, shell, handles input, full command
function exec(tag, cmd, options, callback) {
assert.strictEqual(typeof tag, 'string');
assert.strictEqual(typeof cmd, 'string');
@@ -28,8 +28,10 @@ function exec(tag, cmd, options, callback) {
debug(`${tag} exec: ${cmd}`);
const execOptions = Object.assign({ encoding: 'utf8', shell: false }, options);
// https://github.com/nodejs/node/issues/25231
const cp = child_process.exec(cmd, options, function (error, stdout, stderr) {
const cp = child_process.exec(cmd, execOptions, function (error, stdout, stderr) {
let e = null;
if (error) {
e = new BoxError(BoxError.SHELL_ERROR, `${tag} errored with code ${error.code} message ${error.message}`);
@@ -48,7 +50,7 @@ function exec(tag, cmd, options, callback) {
}
}
// no shell, utf8 encoding, separate args
// default encoding utf8, no shell, separate args
function execFile(tag, file, args, options, callback) {
assert.strictEqual(typeof tag, 'string');
assert.strictEqual(typeof file, 'string');
@@ -58,8 +60,10 @@ function execFile(tag, file, args, options, callback) {
debug(`${tag} exec: ${file}`);
const execOptions = Object.assign({ encoding: 'utf8', shell: false }, options);
// https://github.com/nodejs/node/issues/25231
const cp = child_process.execFile(file, args, options, function (error, stdout, stderr) {
const cp = child_process.execFile(file, args, execOptions, function (error, stdout, stderr) {
let e = null;
if (error) {
e = new BoxError(BoxError.SHELL_ERROR, `${tag} errored with code ${error.code} message ${error.message}`);