diff --git a/lib/fs.js b/lib/fs.js index cde3a582727f80..3852299cb35d3f 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -598,7 +598,6 @@ function openAsBlob(path, options = kEmptyObject) { */ function read(fd, buffer, offsetOrOptions, length, position, callback) { fd = getValidatedFd(fd); - let offset = offsetOrOptions; let params = null; if (arguments.length <= 4) { @@ -690,8 +689,6 @@ ObjectDefineProperty(read, kCustomPromisifyArgsSymbol, * @returns {number} */ function readSync(fd, buffer, offsetOrOptions, length, position) { - fd = getValidatedFd(fd); - validateBuffer(buffer); let offset = offsetOrOptions; @@ -780,7 +777,6 @@ ObjectDefineProperty(readv, kCustomPromisifyArgsSymbol, * @returns {number} */ function readvSync(fd, buffers, position) { - fd = getValidatedFd(fd); validateBufferArray(buffers); if (typeof position !== 'number') @@ -810,7 +806,6 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) { } fd = getValidatedFd(fd); - let offset = offsetOrOptions; if (isArrayBufferView(buffer)) { callback ||= position || length || offset; @@ -881,7 +876,6 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol, * @returns {number} */ function writeSync(fd, buffer, offsetOrOptions, length, position) { - fd = getValidatedFd(fd); const ctx = {}; let result; @@ -971,7 +965,6 @@ ObjectDefineProperty(writev, kCustomPromisifyArgsSymbol, { * @returns {number} */ function writevSync(fd, buffers, position) { - fd = getValidatedFd(fd); validateBufferArray(buffers); if (buffers.length === 0) { diff --git a/src/node_file.cc b/src/node_file.cc index 15e0ff923bc112..9015dbc4a9c6ee 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2314,8 +2314,10 @@ static void WriteBuffer(const FunctionCallbackInfo& args) { const int argc = args.Length(); CHECK_GE(argc, 4); - CHECK(args[0]->IsInt32()); - const int fd = args[0].As()->Value(); + int fd; + if (!GetValidatedFd(env, args[0]).To(&fd)) { + return; + } CHECK(Buffer::HasInstance(args[1])); Local buffer_obj = args[1].As(); @@ -2381,8 +2383,10 @@ static void WriteBuffers(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(args[1]->IsArray()); Local chunks = args[1].As(); @@ -2441,8 +2445,10 @@ static void WriteString(const FunctionCallbackInfo& args) { const int argc = args.Length(); CHECK_GE(argc, 4); - CHECK(args[0]->IsInt32()); - const int fd = args[0].As()->Value(); + int fd; + if (!GetValidatedFd(env, args[0]).To(&fd)) { + return; + } const int64_t pos = GetOffset(args[2]); @@ -2634,8 +2640,10 @@ static void Read(const FunctionCallbackInfo& args) { const int argc = args.Length(); CHECK_GE(argc, 5); - CHECK(args[0]->IsInt32()); - const int fd = args[0].As()->Value(); + int fd; + if (!GetValidatedFd(env, args[0]).To(&fd)) { + return; + } CHECK(Buffer::HasInstance(args[1])); Local buffer_obj = args[1].As(); @@ -2765,8 +2773,10 @@ static void ReadBuffers(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(args[1]->IsArray()); Local buffers = args[1].As();