Skip to content

Commit 33ad86c

Browse files
anonrigmarco-ippolito
authored andcommitted
fs: validate fd from cpp on close
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>
1 parent 34667c0 commit 33ad86c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/fs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ function close(fd, callback = defaultCloseCallback) {
518518

519519
const req = new FSReqCallback();
520520
req.oncomplete = callback;
521-
binding.close(getValidatedFd(fd), req);
521+
binding.close(fd, req);
522522
}
523523

524524
/**
@@ -527,7 +527,7 @@ function close(fd, callback = defaultCloseCallback) {
527527
* @returns {void}
528528
*/
529529
function closeSync(fd) {
530-
binding.close(getValidatedFd(fd));
530+
binding.close(fd);
531531
}
532532

533533
/**

src/node_file.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,10 @@ void Close(const FunctionCallbackInfo<Value>& args) {
984984
const int argc = args.Length();
985985
CHECK_GE(argc, 1);
986986

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

991993
if (argc > 1) { // close(fd, req)

0 commit comments

Comments
 (0)