Skip to content

Commit c6a12cb

Browse files
committed
Changed Batik calls to use execFile instead of exec
In addition to being more secure, execFile (with arguments as an array) should work on all platforms because it does not require a hardcoded quote character. (On windows, quoting with the single ' causes this call to fail.)
1 parent af95c00 commit c6a12cb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/mj-page.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var fs = require('fs');
3030
var path = require('path');
3131
var fmt = require('util').format;
3232
var jsdom = require("jsdom").jsdom;
33-
var exec = require('child_process').exec;
33+
var execFile = require('child_process').execFile;
3434
var speech = require('speech-rule-engine');
3535

3636
var displayMessages = false; // don't log Message.Set() calls
@@ -659,7 +659,7 @@ function MakeIMG() {
659659
function MakePNG() {
660660
if (data.renderer === "PNG") {
661661
var synch = MathJax.Callback(function () {}); // for synchronization with MathJax
662-
var batikCommand = fmt("java -jar %s -dpi %d '%s.svg'",BatikRasterizerPath,data.dpi,tmpfile);
662+
var batikCommands = ['-jar', BatikRasterizerPath, '-dpi', data.dpi, tmpfile + '.svg'];
663663
var tmpSVG = tmpfile+".svg", tmpPNG = tmpfile+".png";
664664
var nodes = document.getElementsByClassName("MathJax_SVG");
665665
var check = function (err) {if (err) {AddError(err.message); return true}}
@@ -677,7 +677,7 @@ function MakePNG() {
677677
].join("\n");
678678
fs.writeFile(tmpSVG,svg,function (err) {
679679
if (check(err)) return PNG(i-1);
680-
exec(batikCommand, function (err,stdout,stderr) {
680+
execFile('java', batikCommands, function (err,stdout,stderr) {
681681
if (check(err)) {fs.unlinkSync(tmpSVG); return PNG(i-1)}
682682
fs.readFile(tmpPNG,null,function (err,buffer) {
683683
if (!check(err)) {

lib/mj-single.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var fs = require('fs');
3131
var path = require('path');
3232
var fmt = require('util').format;
3333
var jsdom = require('jsdom').jsdom;
34-
var exec = require('child_process').exec;
34+
var execFile = require('child_process').execFile;
3535
var speech = require('speech-rule-engine');
3636

3737
var displayMessages = false; // don't log Message.Set() calls
@@ -456,13 +456,13 @@ function GetSVG(result) {
456456
function GetPNG(result) {
457457
var svgfile = result.svgfile; delete result.svgfile;
458458
if (data.png) {
459-
var batikCommand = fmt("java -jar %s -dpi %d '%s.svg'",BatikRasterizerPath,data.dpi,tmpfile);
459+
var batikCommands = ['-jar', BatikRasterizerPath, '-dpi', data.dpi, tmpfile + '.svg'];
460460
var synch = MathJax.Callback(function () {}); // for synchronization with MathJax
461461
var check = function (err) {if (err) {AddError(err.message); synch(); return true}}
462462
var tmpSVG = tmpfile+".svg", tmpPNG = tmpfile+".png";
463463
fs.writeFile(tmpSVG,svgfile,function (err) {
464464
if (check(err)) return;
465-
exec(batikCommand, function (err,stdout,stderr) {
465+
execFile('java', batikCommands, function (err,stdout,stderr) {
466466
if (check(err)) {fs.unlinkSync(tmpSVG); return}
467467
fs.readFile(tmpPNG,null,function (err,buffer) {
468468
result.png = "data:image/png;base64,"+(buffer||"").toString('base64');

0 commit comments

Comments
 (0)