Skip to content

Commit beddb4b

Browse files
committed
lib: fix realpathSync resolving to invalid path
1 parent 4244355 commit beddb4b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/fs.js

+8
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,14 @@ function realpathSync(p, options) {
27312731
}
27322732
resolvedLink = pathModule.resolve(previous, linkTarget);
27332733

2734+
// If resolvedLink is not valid or is a pipe/socket, stop resolving, break out of the loop
2735+
// issue: https://github.com/nodejs/node/issues/54200
2736+
const resolvedLinkStats = binding.lstat(resolvedLink, false, undefined, false /* throwIfNoEntry */);
2737+
if (!resolvedLinkStats || isFileType(resolvedLinkStats, S_IFIFO) ||
2738+
isFileType(resolvedLinkStats, S_IFSOCK)) {
2739+
break;
2740+
}
2741+
27342742
cache?.set(base, resolvedLink);
27352743
if (!isWindows) seenLinks.set(id, linkTarget);
27362744
}

0 commit comments

Comments
 (0)