Skip to content

Commit

Permalink
use fs.lchown rather than fs.chown and thereby fix the symlinks problem
Browse files Browse the repository at this point in the history
isaacs#3 while not causing the TOCTOU vulnerability isaacs#14
  • Loading branch information
Paolo Greppi committed Jan 11, 2018
1 parent c6c4384 commit 0307bb7
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions chownr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@ function chownr (p, uid, gid, cb) {
, errState = null
children.forEach(function (child) {
var pathChild = path.resolve(p, child);
fs.lstat(pathChild, function(er, stats) {
if (er)
return cb(er)
if (!stats.isSymbolicLink())
chownr(pathChild, uid, gid, then)
else
then()
})
chownr(pathChild, uid, gid, then)
})
function then (er) {
if (errState) return
if (er) return cb(errState = er)
if (-- len === 0) return fs.chown(p, uid, gid, cb)
if (-- len === 0) return fs.lchown(p, uid, gid, cb)
}
})
}
Expand Down

0 comments on commit 0307bb7

Please sign in to comment.