Skip to content

Commit 51d7cd5

Browse files
anonrigmarco-ippolito
authored andcommittedMay 3, 2024
fs: validate fd from cpp on fchown
PR-URL: #52051 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
1 parent 33ad86c commit 51d7cd5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
 

‎lib/fs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ function fchown(fd, uid, gid, callback) {
20282028

20292029
const req = new FSReqCallback();
20302030
req.oncomplete = callback;
2031-
binding.fchown(getValidatedFd(fd), uid, gid, req);
2031+
binding.fchown(fd, uid, gid, req);
20322032
}
20332033

20342034
/**
@@ -2042,7 +2042,7 @@ function fchownSync(fd, uid, gid) {
20422042
validateInteger(uid, 'uid', -1, kMaxUserId);
20432043
validateInteger(gid, 'gid', -1, kMaxUserId);
20442044

2045-
binding.fchown(getValidatedFd(fd), uid, gid);
2045+
binding.fchown(fd, uid, gid);
20462046
}
20472047

20482048
/**

‎src/node_file.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -2695,8 +2695,10 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
26952695
const int argc = args.Length();
26962696
CHECK_GE(argc, 3);
26972697

2698-
CHECK(args[0]->IsInt32());
2699-
const int fd = args[0].As<Int32>()->Value();
2698+
int fd;
2699+
if (!GetValidatedFd(env, args[0]).To(&fd)) {
2700+
return;
2701+
}
27002702

27012703
CHECK(IsSafeJsInt(args[1]));
27022704
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());

0 commit comments

Comments
 (0)