Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7697ce0

Browse filesBrowse files
mertcanaltinaduh95
authored andcommitted
fs: remove duplicate fd validation in sync functions
PR-URL: #61361 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
1 parent 9f25cad commit 7697ce0
Copy full SHA for 7697ce0

2 files changed

+20-17Lines changed: 20 additions & 17 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ function openAsBlob(path, options = kEmptyObject) {
597597
*/
598598
function read(fd, buffer, offsetOrOptions, length, position, callback) {
599599
fd = getValidatedFd(fd);
600-
601600
let offset = offsetOrOptions;
602601
let params = null;
603602
if (arguments.length <= 4) {
@@ -689,8 +688,6 @@ ObjectDefineProperty(read, kCustomPromisifyArgsSymbol,
689688
* @returns {number}
690689
*/
691690
function readSync(fd, buffer, offsetOrOptions, length, position) {
692-
fd = getValidatedFd(fd);
693-
694691
validateBuffer(buffer);
695692

696693
let offset = offsetOrOptions;
@@ -779,7 +776,6 @@ ObjectDefineProperty(readv, kCustomPromisifyArgsSymbol,
779776
* @returns {number}
780777
*/
781778
function readvSync(fd, buffers, position) {
782-
fd = getValidatedFd(fd);
783779
validateBufferArray(buffers);
784780

785781
if (typeof position !== 'number')
@@ -809,7 +805,6 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
809805
}
810806

811807
fd = getValidatedFd(fd);
812-
813808
let offset = offsetOrOptions;
814809
if (isArrayBufferView(buffer)) {
815810
callback ||= position || length || offset;
@@ -880,7 +875,6 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol,
880875
* @returns {number}
881876
*/
882877
function writeSync(fd, buffer, offsetOrOptions, length, position) {
883-
fd = getValidatedFd(fd);
884878
const ctx = {};
885879
let result;
886880

@@ -970,7 +964,6 @@ ObjectDefineProperty(writev, kCustomPromisifyArgsSymbol, {
970964
* @returns {number}
971965
*/
972966
function writevSync(fd, buffers, position) {
973-
fd = getValidatedFd(fd);
974967
validateBufferArray(buffers);
975968

976969
if (buffers.length === 0) {
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+20-10Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,8 +2314,10 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
23142314
const int argc = args.Length();
23152315
CHECK_GE(argc, 4);
23162316

2317-
CHECK(args[0]->IsInt32());
2318-
const int fd = args[0].As<Int32>()->Value();
2317+
int fd;
2318+
if (!GetValidatedFd(env, args[0]).To(&fd)) {
2319+
return;
2320+
}
23192321

23202322
CHECK(Buffer::HasInstance(args[1]));
23212323
Local<Object> buffer_obj = args[1].As<Object>();
@@ -2381,8 +2383,10 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
23812383
const int argc = args.Length();
23822384
CHECK_GE(argc, 3);
23832385

2384-
CHECK(args[0]->IsInt32());
2385-
const int fd = args[0].As<Int32>()->Value();
2386+
int fd;
2387+
if (!GetValidatedFd(env, args[0]).To(&fd)) {
2388+
return;
2389+
}
23862390

23872391
CHECK(args[1]->IsArray());
23882392
Local<Array> chunks = args[1].As<Array>();
@@ -2441,8 +2445,10 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
24412445

24422446
const int argc = args.Length();
24432447
CHECK_GE(argc, 4);
2444-
CHECK(args[0]->IsInt32());
2445-
const int fd = args[0].As<Int32>()->Value();
2448+
int fd;
2449+
if (!GetValidatedFd(env, args[0]).To(&fd)) {
2450+
return;
2451+
}
24462452

24472453
const int64_t pos = GetOffset(args[2]);
24482454

@@ -2634,8 +2640,10 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
26342640
const int argc = args.Length();
26352641
CHECK_GE(argc, 5);
26362642

2637-
CHECK(args[0]->IsInt32());
2638-
const int fd = args[0].As<Int32>()->Value();
2643+
int fd;
2644+
if (!GetValidatedFd(env, args[0]).To(&fd)) {
2645+
return;
2646+
}
26392647

26402648
CHECK(Buffer::HasInstance(args[1]));
26412649
Local<Object> buffer_obj = args[1].As<Object>();
@@ -2765,8 +2773,10 @@ static void ReadBuffers(const FunctionCallbackInfo<Value>& args) {
27652773
const int argc = args.Length();
27662774
CHECK_GE(argc, 3);
27672775

2768-
CHECK(args[0]->IsInt32());
2769-
const int fd = args[0].As<Int32>()->Value();
2776+
int fd;
2777+
if (!GetValidatedFd(env, args[0]).To(&fd)) {
2778+
return;
2779+
}
27702780

27712781
CHECK(args[1]->IsArray());
27722782
Local<Array> buffers = args[1].As<Array>();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.