Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Shatskiy <shaackiy@gmail.com>2020-05-14 10:32:38 +0300
committerJames M Snell <jasnell@gmail.com>2020-06-25 21:58:50 +0300
commit82f13fa803ac0b51f42118c26cc947b3101b6078 (patch)
tree1fad8c90783cfc0ff5bcda409548c5250f5d8bf0 /lib/internal/fs
parentb831b081c499a614c1ee3f0272c9de1783395402 (diff)
fs: fix readdir failure when libuv returns UV_DIRENT_UNKNOWN
Fixes: https://github.com/nodejs/node/issues/33348 PR-URL: https://github.com/nodejs/node/pull/33395 Refs: https://github.com/nodejs/node/issues/33348 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/fs')
-rw-r--r--lib/internal/fs/utils.js45
1 files changed, 42 insertions, 3 deletions
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js
index 04ae34e41fd..712bd87d85f 100644
--- a/lib/internal/fs/utils.js
+++ b/lib/internal/fs/utils.js
@@ -173,6 +173,31 @@ function copyObject(source) {
return target;
}
+const bufferSep = Buffer.from(pathModule.sep);
+
+function join(path, name) {
+ if ((typeof path === 'string' || isUint8Array(path)) &&
+ name === undefined) {
+ return path;
+ }
+
+ if (typeof path === 'string' && isUint8Array(name)) {
+ const pathBuffer = Buffer.from(pathModule.join(path, pathModule.sep));
+ return Buffer.concat([pathBuffer, name]);
+ }
+
+ if (typeof path === 'string' && typeof name === 'string') {
+ return pathModule.join(path, name);
+ }
+
+ if (isUint8Array(path) && isUint8Array(name)) {
+ return Buffer.concat([path, bufferSep, name]);
+ }
+
+ throw new ERR_INVALID_ARG_TYPE(
+ 'path', ['string', 'Buffer'], path);
+}
+
function getDirents(path, [names, types], callback) {
let i;
if (typeof callback === 'function') {
@@ -185,7 +210,14 @@ function getDirents(path, [names, types], callback) {
const name = names[i];
const idx = i;
toFinish++;
- lazyLoadFs().lstat(pathModule.join(path, name), (err, stats) => {
+ let filepath;
+ try {
+ filepath = join(path, name);
+ } catch (err) {
+ callback(err);
+ return;
+ }
+ lazyLoadFs().lstat(filepath, (err, stats) => {
if (err) {
callback(err);
return;
@@ -214,7 +246,14 @@ function getDirents(path, [names, types], callback) {
function getDirent(path, name, type, callback) {
if (typeof callback === 'function') {
if (type === UV_DIRENT_UNKNOWN) {
- lazyLoadFs().lstat(pathModule.join(path, name), (err, stats) => {
+ let filepath;
+ try {
+ filepath = join(path, name);
+ } catch (err) {
+ callback(err);
+ return;
+ }
+ lazyLoadFs().lstat(filepath, (err, stats) => {
if (err) {
callback(err);
return;
@@ -225,7 +264,7 @@ function getDirent(path, name, type, callback) {
callback(null, new Dirent(name, type));
}
} else if (type === UV_DIRENT_UNKNOWN) {
- const stats = lazyLoadFs().lstatSync(pathModule.join(path, name));
+ const stats = lazyLoadFs().lstatSync(join(path, name));
return new DirentFromStats(name, stats);
} else {
return new Dirent(name, type);