Skip to content

Commit 5402b26

Browse files
committed
fs: fix chown abort
This syncs the type assertion introduced in the referenced PR in the C++ side. Since chown, lchown, and fchown can accept -1 as a value for uid and gid, we should also accept signed integers from the JS side. Fixes: nodejs#37995 Refs: nodejs#31694
1 parent 01d8b39 commit 5402b26

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/node_file.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,11 +2184,11 @@ static void Chown(const FunctionCallbackInfo<Value>& args) {
21842184
BufferValue path(env->isolate(), args[0]);
21852185
CHECK_NOT_NULL(*path);
21862186

2187-
CHECK(args[1]->IsUint32());
2188-
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
2187+
CHECK(IsSafeJsInt(args[1]));
2188+
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());
21892189

2190-
CHECK(args[2]->IsUint32());
2191-
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());
2190+
CHECK(IsSafeJsInt(args[2]));
2191+
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
21922192

21932193
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
21942194
if (req_wrap_async != nullptr) { // chown(path, uid, gid, req)
@@ -2217,11 +2217,11 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
22172217
CHECK(args[0]->IsInt32());
22182218
const int fd = args[0].As<Int32>()->Value();
22192219

2220-
CHECK(args[1]->IsUint32());
2221-
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
2220+
CHECK(IsSafeJsInt(args[1]));
2221+
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());
22222222

2223-
CHECK(args[2]->IsUint32());
2224-
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());
2223+
CHECK(IsSafeJsInt(args[2]));
2224+
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
22252225

22262226
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22272227
if (req_wrap_async != nullptr) { // fchown(fd, uid, gid, req)
@@ -2247,11 +2247,11 @@ static void LChown(const FunctionCallbackInfo<Value>& args) {
22472247
BufferValue path(env->isolate(), args[0]);
22482248
CHECK_NOT_NULL(*path);
22492249

2250-
CHECK(args[1]->IsUint32());
2251-
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
2250+
CHECK(IsSafeJsInt(args[1]));
2251+
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());
22522252

2253-
CHECK(args[2]->IsUint32());
2254-
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());
2253+
CHECK(IsSafeJsInt(args[2]));
2254+
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
22552255

22562256
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22572257
if (req_wrap_async != nullptr) { // lchown(path, uid, gid, req)

0 commit comments

Comments
 (0)