Skip to content

Commit

Permalink
fs: validate fd from cpp on close
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
anonrig authored and marco-ippolito committed May 3, 2024
1 parent 34667c0 commit 33ad86c
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 @@ -518,7 +518,7 @@ function close(fd, callback = defaultCloseCallback) {

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

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

/**
Expand Down
6 changes: 4 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,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

0 comments on commit 33ad86c

Please sign in to comment.