Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Enforce pid to be a number, do not allow shell expansion in commands
Browse files Browse the repository at this point in the history
  • Loading branch information
robotlolita committed Jul 23, 2020
1 parent b6d819e commit 7684811
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
3 changes: 3 additions & 0 deletions lib/linux.js
Expand Up @@ -45,5 +45,8 @@ function list() {
// @type: (Number) -> Task(Error, Undefined)
exports.kill = kill;
function kill(pid) {
if (typeof pid !== "number") {
throw new TypeError(`Expected pid to be a number`);
}
return shell('kill', ['-9', pid]).map(K(undefined));
}
9 changes: 2 additions & 7 deletions lib/utils.js
Expand Up @@ -6,14 +6,10 @@

// -- Dependencies -----------------------------------------------------
var Task = require('data.task');
var exec = require('child_process').exec;
var exec = require('child_process').execFile;
var compose = require('core.lambda').compose;
var unary = require('core.arity').unary;

// -- Helpers and aliases ----------------------------------------------
var escapeArg = JSON.stringify;


// -- Implementation ---------------------------------------------------

// ### function: shell(command, args)
Expand All @@ -23,9 +19,8 @@ var escapeArg = JSON.stringify;
// @type: (String, [String]) -> Task(Error, { output: String, error: String })
exports.shell = shell;
function shell(cmd, args) {
var command = cmd + ' ' + args.map(unary(compose(escapeArg)(String))).join(' ');
return new Task(function(reject, resolve) {
exec(command, function(error, stdout, stderr) {
exec(cmd, args, function(error, stdout, stderr) {
if (error) reject(error);
else resolve({ output: stdout, error: stderr });
});
Expand Down
7 changes: 2 additions & 5 deletions package.json
@@ -1,12 +1,10 @@
{
"name": "xps",
"version": "0.0.0-semantically-released",
"version": "1.0.3",
"description": "Cross-platform library for listing and killing processes.",
"main": "./lib/index.js",
"scripts": {
"test": "make test",
"prepublish": "semantic-release pre",
"postpublish": "semantic-release post"
"test": "make test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,7 +32,6 @@
"ms-task": "^1.1.0"
},
"devDependencies": {
"semantic-release": "^3.3.1",
"specify-assertions": "^1.0.0",
"specify-core": "^1.0.1",
"specify-reporter-spec": "^1.0.0",
Expand Down

0 comments on commit 7684811

Please sign in to comment.