Skip to content

Commit

Permalink
Fix arbitrary command injection, CWE-264
Browse files Browse the repository at this point in the history
  • Loading branch information
Logikgate committed May 14, 2018
1 parent dd07962 commit 99b23e6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/linux.js
@@ -1,11 +1,11 @@
var exec = require('child_process').exec;
var execFile = require('child_process').execFile;

module.exports = function (iface, callback) {
exec("cat /sys/class/net/" + iface + "/address", function (err, out) {
execFile("cat", ["/sys/class/net/", iface, "/address"], function (err, out) {

This comment has been minimized.

Copy link
@mikroskeem

mikroskeem Jun 11, 2018

There's a fs#readFile for reading files, you don't need to use cat and exec* functions for that.

Besides that, I'd use path#basename on iface as well to avoid path traversal (even though I doubt that anyone would really use file named address in production, but you'll never know 😉)

if (err) {
callback(err, null);
return;
}
callback(null, out.trim().toLowerCase());
});
};
};
4 changes: 2 additions & 2 deletions lib/macosx.js
@@ -1,7 +1,7 @@
var exec = require('child_process').exec;
var execFile = require('child_process').execFile;

module.exports = function (iface, callback) {
exec("networksetup -getmacaddress " + iface, function (err, out) {
execFile("networksetup", ["-getmacaddress", iface], function (err, out) {
if (err) {
callback(err, null);
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/unix.js
@@ -1,7 +1,7 @@
var exec = require('child_process').exec;
var execFile = require('child_process').execFile;

module.exports = function (iface, callback) {
exec("ifconfig " + iface, function (err, out) {
execFile("ifconfig", [iface], function (err, out) {
if (err) {
callback(err, null);
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/windows.js
@@ -1,4 +1,4 @@
var exec = require('child_process').exec;
var execFile = require('child_process').execFile;

var regexRegex = /[-\/\\^$*+?.()|[\]{}]/g;

Expand All @@ -7,7 +7,7 @@ function escape(string) {
}

module.exports = function (iface, callback) {
exec("ipconfig /all", function (err, out) {
execFile("ipconfig", ["/all"], function (err, out) {
if (err) {
callback(err, null);
return;
Expand Down

0 comments on commit 99b23e6

Please sign in to comment.