Skip to content
Permalink
Browse files Browse the repository at this point in the history
address security vulnerability
  • Loading branch information
natelong committed Dec 12, 2022
1 parent d37c2b9 commit ae42e25
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 21 additions & 5 deletions p4.js
@@ -1,19 +1,35 @@
/*jshint node:true*/
"use strict";

var exec = require("child_process").exec;
var exec = require("child_process").spawn;

function runCommand(command, args, done) {
if(typeof args === "function") {
done = args;
args = "";
}

exec("p4 " + command + " " + (args || ""), function(err, stdOut, stdErr) {
if(err) return done(err);
if(stdErr) return done(new Error(stdErr));
if(!Array.isArray(args)) {
args = [args];
}
args.unshift(command);

var child = spawn("p4", args);
var stdOutBuf = "";
var stdErrBuf = "";

child.stdout.on("data", (data) => stdOutBuf += data);
child.stderr.on("data", (data) => stdErrBuf += data)
child.on("exit", (code) => {
if (code !== 0) {
return done(new Error(`p4 subcommand exited with return code ${}`));
}

if (stdErrBuf.length > 0) {
return done(new Error(stdErrBuf));
}

done(null, stdOut);
done(null, stdOutBuf);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "p4",
"version": "0.0.6",
"version": "0.0.7",
"description": "A small utility library for dealing with Perforce",
"main": "p4.js",
"author": "Nate Long <long.nathaniel@gmail.com>",
Expand Down

0 comments on commit ae42e25

Please sign in to comment.