Permalink
Browse files

Linux sudo wrapper: Check if bin actually exists.

  • Loading branch information...
1 parent e427012 commit 7b59b0e0fccddee1769749bb15a8d0329510640d @tomas tomas committed Mar 7, 2014
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/system/linux/sudo.js
View
@@ -1,9 +1,9 @@
-var spawn = require('child_process').spawn,
+var fs = require('fs'),
+ spawn = require('child_process').spawn,
sudo_bin = '/usr/bin/sudo',
pass_required = 'a password is required',
sudo_args = ['-n'];
-
module.exports = function(bin, args, cb){
var cmd = [bin].concat(args),
@@ -12,6 +12,10 @@ module.exports = function(bin, args, cb){
err = '',
returned = false;
+ var exists = fs.existsSync(bin);
+ if (!exists)
+ return cb(new Error('Command not found: ' + bin));
+
var sudo_env = process.env;
sudo_env.LANG = 'en'; // to avoid sudo i18n that breaks our out.match()
@@ -25,11 +29,11 @@ module.exports = function(bin, args, cb){
var child = spawn(sudo_bin, all_args, opts);
- child.stdout.on('data', function(data){
+ child.stdout.on('data', function(data) {
out += data.toString();
})
- child.stderr.on('data', function(data){
+ child.stderr.on('data', function(data) {
if (data.toString().match(pass_required))
return done(new Error('No sudo access for ' + bin));

0 comments on commit 7b59b0e

Please sign in to comment.