Skip to content

Commit

Permalink
Merge pull request #93 from tim-sueberkrueb/master
Browse files Browse the repository at this point in the history
Properly escape password everywhere
  • Loading branch information
mariogrip committed Feb 17, 2018
2 parents 59751f0 + 8226804 commit d9c0a51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const start = (password, sudo, callback) => {
stop(err => {
var cmd="";
if (utils.needRoot() && sudo)
cmd += "echo " + password + " | sudo -S "
cmd += utils.sudoCommand(password);
cmd += adb + " -P " + PORT + " start-server";
utils.platfromToolsExecAsar("adb", (platfromToolsExecAsar) => {
platfromToolsExecAsar.exec(cmd, (c, r, e) => {
Expand Down
10 changes: 5 additions & 5 deletions src/fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var waitForDevice = (password, callback) => {
utils.log.debug("fastboot: wait for device");
var cmd = "";
if (utils.needRoot())
cmd += "echo " + password + " | sudo -S "
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " devices";
var stop;
utils.platfromToolsExecAsar("fastboot", (asarExec) => {
Expand Down Expand Up @@ -106,7 +106,7 @@ var flash = (images, callback, password) => {
var cmd = "";
images.forEach((image, l) => {
if (utils.needRoot())
cmd += "echo " + password + " | sudo -S "
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " flash " + image.type + " \"" + path.join(image.path, path.basename(image.url)) + "\"";
if (l !== images.length - 1)
cmd += " && "
Expand Down Expand Up @@ -135,7 +135,7 @@ image object format
var boot = (image, password, callback) => {
var cmd="";
if (utils.needRoot())
cmd += "echo " + password + " | sudo -S "
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " boot \"" + path.join(image.path, path.basename(image.url)) + "\"";
utils.platfromToolsExecAsar("fastboot", (asarExec) => {
asarExec.exec(cmd, (c, r, e) => {
Expand All @@ -153,7 +153,7 @@ var format = (partitions, password, callback) => {
var cmd="";
partitions.forEach((partition, l) => {
if (utils.needRoot())
cmd += "echo " + password + " | sudo -S "
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " format " + partition;
if (l !== partitions.length - 1)
cmd += " && "
Expand All @@ -174,7 +174,7 @@ args; array, string, function
var oem = (command, password, callback) => {
var cmd="";
if (utils.needRoot())
cmd += "echo " + password + " | sudo -S "
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " oem " + command;
utils.platfromToolsExecAsar("fastboot", (asarExec) => {
asarExec.exec(cmd, (c, r, e) => {
Expand Down
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ var die = (e) => {
process.exit(1);
}

var sudoCommand = (password) => {
return "echo '" + password.replace(/\'/g, "'\\''") + "' | sudo -S ";
}

var checkPassword = (password, callback) => {
if (!needRoot()) {
log.debug("no root needed")
callback(true);
return;
}
log.debug("checking password")
exec("echo \"" + password.replace(/\"/g, "\\\"") + "\" | sudo -S echo correct", (err, output) => {
exec(sudoCommand(password) + "echo correct", (err, output) => {
if(err){
if (err.message.includes("incorrect password")) {
log.debug("incorrect password")
Expand Down Expand Up @@ -450,6 +454,7 @@ module.exports = {
getPlatformTools: getPlatformTools,
getUbportDir: getUbportDir,
needRoot: needRoot,
sudoCommand: sudoCommand,
checkPassword: checkPassword,
debugScreen: debugScreen,
debugTrigger: debugTrigger,
Expand Down

0 comments on commit d9c0a51

Please sign in to comment.