Skip to content

Commit 033f985

Browse files
theanarkhmarco-ippolito
authored andcommittedJun 17, 2024
src: use S_ISDIR to check if the file is a directory
PR-URL: #52164 Fixes: #52159 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 954d2ad commit 033f985

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
@@ -1151,7 +1151,7 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
11511151
int rc = uv_fs_stat(env->event_loop(), &req, *path, nullptr);
11521152
if (rc == 0) {
11531153
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
1154-
rc = !!(s->st_mode & S_IFDIR);
1154+
rc = S_ISDIR(s->st_mode);
11551155
}
11561156
uv_fs_req_cleanup(&req);
11571157

@@ -3079,7 +3079,7 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
30793079

30803080
if (rc == 0) {
30813081
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
3082-
rc = !!(s->st_mode & S_IFDIR);
3082+
rc = S_ISDIR(s->st_mode);
30833083
}
30843084

30853085
uv_fs_req_cleanup(&req);

‎src/permission/fs_permission.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ std::string WildcardIfDir(const std::string& res) noexcept {
2020
int rc = uv_fs_stat(nullptr, &req, res.c_str(), nullptr);
2121
if (rc == 0) {
2222
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
23-
if (s->st_mode & S_IFDIR) {
23+
if ((s->st_mode & S_IFMT) == S_IFDIR) {
2424
// add wildcard when directory
2525
if (res.back() == node::kPathSeparator) {
2626
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)
Please sign in to comment.