Skip to content

Commit

Permalink
修复密码中有单引号时的转义问题。 #255 #188
Browse files Browse the repository at this point in the history
  • Loading branch information
oldj committed Aug 29, 2017
1 parent 91070dc commit 1fbd02b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ src/build
src/dist
dist
projectFilesBackup
.DS_Store
*.DS_Store
tmp
*.js.map

Expand Down
14 changes: 14 additions & 0 deletions app/libs/safe-pswd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* safe-pswd
* @author oldj
* @blog https://oldj.net
*/

'use strict'

module.exports = pswd => {
return pswd
.replace(/\\/g, '\\\\')
//.replace(/'/g, "\\''")
.replace(/'/g, '\\x27')
}
9 changes: 3 additions & 6 deletions app/server/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const md5File = require('md5-file')
const applyAfter_Unix = require('./applyAfter_Unix')
const platform = process.platform
const svr = require('./svr')
const version = require('../version').version.join('.')
//const version = require('../version').version.join('.')

let sudo_pswd = ''
let lang = null
Expand Down Expand Up @@ -54,12 +54,8 @@ function apply_Unix (content, callback) {
`cat "${tmp_fn}" > ${sys_hosts_path}`
, `rm -rf ${tmp_fn}`
].join(' && ')
} else {

sudo_pswd = sudo_pswd
.replace(/'/g, '\\x27')
.replace(/\\/g, '\\\\')

} else {
cmd = [
`echo '${sudo_pswd}' | sudo -S chmod 777 ${sys_hosts_path}`
, `cat "${tmp_fn}" > ${sys_hosts_path}`
Expand All @@ -71,6 +67,7 @@ function apply_Unix (content, callback) {
return cmd
})
.then(cmd => {
//console.log('cmd: ' + cmd)
exec(cmd, function (error, stdout, stderr) {
// command output is in stdout
if (!error) {
Expand Down
6 changes: 5 additions & 1 deletion app/server/sudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@

'use strict'

const safePSWD = require('../libs/safe-pswd')

module.exports = svr => {

let _resolve
let _reject

svr.once('sudo_pswd', (pswd) => {
svr.once('sudo_pswd', pswd => {
svr.removeAllListeners('sudo_cancel')

try {
pswd = safePSWD(pswd)
_resolve(pswd)
} catch (e) {
console.log(e)
Expand Down
4 changes: 2 additions & 2 deletions app/ui/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports.version = [3,3,7,5305];
exports.version = [3,3,7,5306];

1 comment on commit 1fbd02b

@oldj
Copy link
Owner Author

@oldj oldj commented on 1fbd02b Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.