File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -89,8 +89,6 @@ function close(fd) {
89
89
}
90
90
91
91
function fsync ( fd ) {
92
- fd = getValidatedFd ( fd ) ;
93
-
94
92
return binding . fsyncSync ( fd ) ;
95
93
}
96
94
Original file line number Diff line number Diff line change @@ -116,6 +116,24 @@ inline int64_t GetOffset(Local<Value> value) {
116
116
return IsSafeJsInt (value) ? value.As <Integer>()->Value () : -1 ;
117
117
}
118
118
119
+ inline int GetValidatedFd (Environment* env, Local<Value> value) {
120
+ if (!value->IsInt32 ()) {
121
+ env->isolate ()->ThrowException (ERR_INVALID_ARG_TYPE (
122
+ env->isolate (), " Invalid argument. The fd must be int32." ));
123
+ return 1 << 30 ;
124
+ }
125
+
126
+ const int fd = value.As <Int32>()->Value ();
127
+
128
+ if (fd < 0 || fd > INT32_MAX) {
129
+ env->isolate ()->ThrowException (ERR_OUT_OF_RANGE (
130
+ env->isolate (), " It must be >= 0 && <= INT32_MAX. Received %d" , fd));
131
+ return 1 << 30 ;
132
+ }
133
+
134
+ return fd;
135
+ }
136
+
119
137
static const char * get_fs_func_name_by_type (uv_fs_type req_type) {
120
138
switch (req_type) {
121
139
#define FS_TYPE_TO_NAME (type, name ) \
@@ -1647,10 +1665,8 @@ static void FsyncSync(const FunctionCallbackInfo<Value>& args) {
1647
1665
const int argc = args.Length ();
1648
1666
CHECK_GE (argc, 1 );
1649
1667
1650
- CHECK (args[0 ]->IsInt32 ());
1651
-
1652
- const int fd = args[0 ].As <Int32>()->Value ();
1653
- CHECK_GE (fd, 0 );
1668
+ const int fd = GetValidatedFd (env, args[0 ]);
1669
+ if (fd == (1 << 30 )) return ;
1654
1670
1655
1671
uv_fs_t req;
1656
1672
FS_SYNC_TRACE_BEGIN (fsync );
You can’t perform that action at this time.
0 commit comments