Skip to content

Commit 82eeadb

Browse files
cjihrigtargos
authored andcommitted
fs: use consistent buffer array validation
This commit updates fs.writev() and fs.writevSync() to use the same validation method as filehandle.writev(). PR-URL: #29186 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 81f3eb5 commit 82eeadb

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

‎lib/fs.js‎

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const{
7272
stringToFlags,
7373
stringToSymlinkType,
7474
toUnixTimestamp,
75+
validateBufferArray,
7576
validateOffsetLengthRead,
7677
validateOffsetLengthWrite,
7778
validatePath,
@@ -142,19 +143,6 @@ function maybeCallback(cb){
142143
thrownewERR_INVALID_CALLBACK(cb);
143144
}
144145

145-
functionisBuffersArray(value){
146-
if(!Array.isArray(value))
147-
returnfalse;
148-
149-
for(vari=0;i<value.length;i+=1){
150-
if(!isArrayBufferView(value[i])){
151-
returnfalse;
152-
}
153-
}
154-
155-
returntrue;
156-
}
157-
158146
// Ensure that callbacks run in the global context. Only use this function
159147
// for callbacks that are passed to the binding layer, callbacks that are
160148
// invoked from JS already run in the proper scope.
@@ -610,10 +598,7 @@ function writev(fd, buffers, position, callback){
610598
}
611599

612600
validateInt32(fd,'fd',0);
613-
614-
if(!isBuffersArray(buffers)){
615-
thrownewERR_INVALID_ARG_TYPE('buffers','ArrayBufferView[]',buffers);
616-
}
601+
validateBufferArray(buffers);
617602

618603
constreq=newFSReqCallback();
619604
req.oncomplete=wrapper;
@@ -631,15 +616,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs,{
631616
enumerable: false
632617
});
633618

634-
// fs.writevSync(fd, buffers[, position]);
635619
functionwritevSync(fd,buffers,position){
636-
637620
validateInt32(fd,'fd',0);
638-
constctx={};
621+
validateBufferArray(buffers);
639622

640-
if(!isBuffersArray(buffers)){
641-
thrownewERR_INVALID_ARG_TYPE('buffers','ArrayBufferView[]',buffers);
642-
}
623+
constctx={};
643624

644625
if(typeofposition!=='number')
645626
position=null;

0 commit comments

Comments
(0)