From aec6962039c06b38ea92cd2cdcc704b10adb7198 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 5 Dec 2016 23:28:47 +0000 Subject: [PATCH] Don't print env vars if Node's execFileSync fails Just print the error message, to avoid printing sensitive information (like API access tokens). --- scripts/archive.js | 6 +++--- scripts/create_ico.js | 6 +++--- scripts/helpers.js | 10 ++++++++++ scripts/potomo.js | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/scripts/archive.js b/scripts/archive.js index da54b353..8d84f17f 100644 --- a/scripts/archive.js +++ b/scripts/archive.js @@ -10,12 +10,12 @@ const os = require('os'); const helpers = require('./helpers'); function getGitDescription() { - const describe = String(childProcess.execFileSync('git', [ + const describe = String(helpers.safeExecFileSync('git', [ 'describe', '--tags', '--long', ])).slice(0, -1); - let branch = String(childProcess.execFileSync('git', [ + let branch = String(helpers.safeExecFileSync('git', [ 'rev-parse', '--abbrev-ref', 'HEAD', @@ -66,7 +66,7 @@ function compress(sourcePath, destPath) { // The last argument must have a leading dot for the subdirectory not to // be present in the archive, but path.join removes it, so it's prefixed. - return childProcess.execFileSync(sevenzipPath, [ + return helpers.safeExecFileSync(sevenzipPath, [ 'a', '-r', filename, diff --git a/scripts/create_ico.js b/scripts/create_ico.js index 52ef7074..e4fcb4b8 100644 --- a/scripts/create_ico.js +++ b/scripts/create_ico.js @@ -1,4 +1,4 @@ -const childProcess = require('child_process'); +const helpers = require('./helpers'); const fs = require('fs-extra'); const path = require('path'); @@ -15,7 +15,7 @@ sizes.forEach((size) => { const pngFile = path.join(buildDirectory, `icon-${size}.png`); convertArgs.push(pngFile); - childProcess.execFileSync('inkscape', [ + helpers.safeExecFileSync('inkscape', [ '-z', '-e', pngFile, @@ -28,4 +28,4 @@ sizes.forEach((size) => { }); convertArgs.push(outputPath); -childProcess.execFileSync('convert', convertArgs); +helpers.safeExecFileSync('convert', convertArgs); diff --git a/scripts/helpers.js b/scripts/helpers.js index 88428277..71968438 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -1,5 +1,6 @@ // Helper functions shared across scripts. 'use strict'; +const childProcess = require('child_process'); const path = require('path'); const fs = require('fs'); const os = require('os'); @@ -87,7 +88,16 @@ function getMetadataValidatorBinaryPaths(rootPath) { return getBinaryPaths(rootPath, file); } +function safeExecFileSync(file, args, options) { + try { + childProcess.execFileSync(file, args, options); + } catch (error) { + throw new Error(error.message); + } +} + module.exports.fileExists = fileExists; module.exports.getAppReleasePaths = getAppReleasePaths; module.exports.getApiBinaryPaths = getApiBinaryPaths; module.exports.getMetadataValidatorBinaryPaths = getMetadataValidatorBinaryPaths; +module.exports.safeExecFileSync = safeExecFileSync; diff --git a/scripts/potomo.js b/scripts/potomo.js index 1ad999ea..210092f6 100644 --- a/scripts/potomo.js +++ b/scripts/potomo.js @@ -21,7 +21,7 @@ fs.readdirSync(l10nPath).forEach((file) => { fs.accessSync(poPath, fs.R_OK); - childProcess.execFileSync('msgfmt', [ + helpers.safeExecFileSync('msgfmt', [ poPath, '-o', moPath,