Skip to content

Commit bcc7d1c

Browse files
author
bcanzanella
committed
Node.js crash on Windows when no read permissions for the disk root or User folder
nodejs#3977
1 parent b148cbe commit bcc7d1c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/fs.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,17 @@ fs.realpathSync = function realpathSync(p, cache) {
12641264
// some known symbolic link. no need to stat again.
12651265
resolvedLink = cache[base];
12661266
} else {
1267-
var stat = fs.lstatSync(base);
1268-
if (!stat.isSymbolicLink()) {
1267+
var stat = null;
1268+
try {
1269+
stat = fs.lstatSync(base);
1270+
} catch (e) {
1271+
// Windows throws an exception if NTFS permissions are missing
1272+
if (!isWindows || e.code != 'EPERM') {
1273+
throw e;
1274+
}
1275+
}
1276+
1277+
if (stat == null || !stat.isSymbolicLink()) {
12691278
knownHard[base] = true;
12701279
if (cache) cache[base] = base;
12711280
continue;

lib/module.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,10 @@ Module._initPaths = function() {
511511
var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
512512

513513
if (homeDir) {
514-
paths.unshift(path.resolve(homeDir, '.node_libraries'));
515-
paths.unshift(path.resolve(homeDir, '.node_modules'));
514+
try {
515+
paths.unshift(path.resolve(homeDir, '.node_libraries'));
516+
paths.unshift(path.resolve(homeDir, '.node_modules'));
517+
} catch(ex) { }
516518
}
517519

518520
if (process.env['NODE_PATH']) {

0 commit comments

Comments
 (0)