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: https://github.com/nodejs/node/pull/29186
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
cjihrig 2019-08-17 15:03:46 -04:00
parent 3273d0e951
commit 8d100c21c5
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5

View File

@ -72,6 +72,7 @@ const {
stringToFlags,
stringToSymlinkType,
toUnixTimestamp,
validateBufferArray,
validateOffsetLengthRead,
validateOffsetLengthWrite,
validatePath,
@ -142,19 +143,6 @@ function maybeCallback(cb) {
throw new ERR_INVALID_CALLBACK(cb);
}
function isBuffersArray(value) {
if (!Array.isArray(value))
return false;
for (var i = 0; i < value.length; i += 1) {
if (!isArrayBufferView(value[i])) {
return false;
}
}
return true;
}
// Ensure that callbacks run in the global context. Only use this function
// for callbacks that are passed to the binding layer, callbacks that are
// invoked from JS already run in the proper scope.
@ -626,10 +614,7 @@ function writev(fd, buffers, position, callback) {
}
validateInt32(fd, 'fd', 0);
if (!isBuffersArray(buffers)) {
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
}
validateBufferArray(buffers);
const req = new FSReqCallback();
req.oncomplete = wrapper;
@ -647,15 +632,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs, {
enumerable: false
});
// fs.writevSync(fd, buffers[, position]);
function writevSync(fd, buffers, position) {
validateInt32(fd, 'fd', 0);
const ctx = {};
validateBufferArray(buffers);
if (!isBuffersArray(buffers)) {
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
}
const ctx = {};
if (typeof position !== 'number')
position = null;