Skip to content

Commit 033f985

Browse files
theanarkhmarco-ippolito
authored andcommitted
src: use S_ISDIR to check if the file is a directory
PR-URL: #52164Fixes: #52159 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
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‎

Lines changed: 2 additions & 2 deletions
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
constuv_stat_t* const s = static_cast<constuv_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
constuv_stat_t* const s = static_cast<constuv_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‎

Lines changed: 1 addition & 1 deletion
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
constuv_stat_t* const s = static_cast<constuv_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 + "*";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constfs=require('fs');
4+
constnet=require('net');
5+
6+
consttmpdir=require('../common/tmpdir');
7+
tmpdir.refresh();
8+
9+
constserver=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)