From aa26abf25b770491981b0188496dae878c5d48a6 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 11 Mar 2024 21:44:04 -0400 Subject: [PATCH] fs: validate fd from cpp on `fchown` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/52051 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Paolo Insogna Reviewed-By: Mohammed Keyvanzadeh --- lib/fs.js | 4 ++-- src/node_file.cc | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 8080c6ac756191..f92bdbd5d09691 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2028,7 +2028,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); } /** @@ -2042,7 +2042,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); } /** diff --git a/src/node_file.cc b/src/node_file.cc index 4236debfc70ede..178c9fc84a095b 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2695,8 +2695,10 @@ static void FChown(const FunctionCallbackInfo& args) { const int argc = args.Length(); CHECK_GE(argc, 3); - CHECK(args[0]->IsInt32()); - const int fd = args[0].As()->Value(); + int fd; + if (!GetValidatedFd(env, args[0]).To(&fd)) { + return; + } CHECK(IsSafeJsInt(args[1])); const uv_uid_t uid = static_cast(args[1].As()->Value());