Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: validate remaining fd calls from cpp #52051

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ function close(fd, callback = defaultCloseCallback) {

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

/**
Expand All @@ -531,7 +531,7 @@ function close(fd, callback = defaultCloseCallback) {
* @returns {void}
*/
function closeSync(fd) {
binding.close(getValidatedFd(fd));
binding.close(fd);
}

/**
Expand Down Expand Up @@ -2034,7 +2034,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 @@ -2048,7 +2048,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
12 changes: 8 additions & 4 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,10 @@ void Close(const FunctionCallbackInfo<Value>& args) {
const int argc = args.Length();
CHECK_GE(argc, 1);

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

if (argc > 1) { // close(fd, req)
Expand Down Expand Up @@ -2591,8 +2593,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
Loading