Skip to content

Commit

Permalink
fs: validate fd from cpp on fchown
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
anonrig authored and nodejs-github-bot committed Mar 14, 2024
1 parent 9ac1fe0 commit 639c096
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ function fchown(fd, uid, gid, callback) {

const req = new FSReqCallback();
req.oncomplete = callback;
binding.fchown(getValidatedFd(fd), uid, gid, req);
binding.fchown(fd, uid, gid, req);
}

/**
Expand All @@ -2044,7 +2044,7 @@ function fchownSync(fd, uid, gid) {
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);

binding.fchown(getValidatedFd(fd), uid, gid);
binding.fchown(fd, uid, gid);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2598,8 +2598,10 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
const int argc = args.Length();
CHECK_GE(argc, 3);

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

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

0 comments on commit 639c096

Please sign in to comment.