Skip to content

Commit 639c096

Browse files
anonrignodejs-github-bot
authored andcommitted
fs: validate fd from cpp on fchown
PR-URL: #52051 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
1 parent 9ac1fe0 commit 639c096

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ function fchown(fd, uid, gid, callback) {
20302030

20312031
const req = new FSReqCallback();
20322032
req.oncomplete = callback;
2033-
binding.fchown(getValidatedFd(fd), uid, gid, req);
2033+
binding.fchown(fd, uid, gid, req);
20342034
}
20352035

20362036
/**
@@ -2044,7 +2044,7 @@ function fchownSync(fd, uid, gid) {
20442044
validateInteger(uid, 'uid', -1, kMaxUserId);
20452045
validateInteger(gid, 'gid', -1, kMaxUserId);
20462046

2047-
binding.fchown(getValidatedFd(fd), uid, gid);
2047+
binding.fchown(fd, uid, gid);
20482048
}
20492049

20502050
/**

src/node_file.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,8 +2598,10 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
25982598
const int argc = args.Length();
25992599
CHECK_GE(argc, 3);
26002600

2601-
CHECK(args[0]->IsInt32());
2602-
const int fd = args[0].As<Int32>()->Value();
2601+
int fd;
2602+
if (!GetValidatedFd(env, args[0]).To(&fd)) {
2603+
return;
2604+
}
26032605

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

0 commit comments

Comments
 (0)