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: nodejs#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 rdw-msft committed Mar 26, 2024
1 parent de32c1a commit 60bf772
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 60bf772

Please sign in to comment.