Skip to content

Commit fca38b2

Browse files
theanarkhtargos
authored andcommitted
src: use S_ISDIR to check if the file is a directory
PR-URL: #52164 Fixes: #52159 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1f7c2a9 commit fca38b2

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/node_file.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
10541054
int rc = uv_fs_stat(env->event_loop(), &req, *path, nullptr);
10551055
if (rc == 0) {
10561056
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
1057-
rc = !!(s->st_mode & S_IFDIR);
1057+
rc = S_ISDIR(s->st_mode);
10581058
}
10591059
uv_fs_req_cleanup(&req);
10601060

@@ -2982,7 +2982,7 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
29822982

29832983
if (rc == 0) {
29842984
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
2985-
rc = !!(s->st_mode & S_IFDIR);
2985+
rc = S_ISDIR(s->st_mode);
29862986
}
29872987

29882988
uv_fs_req_cleanup(&req);

src/permission/fs_permission.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ std::string WildcardIfDir(const std::string& res) noexcept {
2121
int rc = uv_fs_stat(nullptr, &req, res.c_str(), nullptr);
2222
if (rc == 0) {
2323
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
24-
if (s->st_mode & S_IFDIR) {
24+
if ((s->st_mode & S_IFMT) == S_IFDIR) {
2525
// add wildcard when directory
2626
if (res.back() == node::kPathSeparator) {
2727
return res + "*";
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const common = require('../common');
3+
const fs = require('fs');
4+
const net = require('net');
5+
6+
const tmpdir = require('../common/tmpdir');
7+
tmpdir.refresh();
8+
9+
const server = net.createServer().listen(common.PIPE, common.mustCall(() => {
10+
// The process should not crash
11+
// See https://github.com/nodejs/node/issues/52159
12+
fs.readdirSync(tmpdir.path, { recursive: true });
13+
server.close();
14+
}));

0 commit comments

Comments
 (0)