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:
parent
3273d0e951
commit
8d100c21c5
27
lib/fs.js
27
lib/fs.js
@ -72,6 +72,7 @@ const {
|
|||||||
stringToFlags,
|
stringToFlags,
|
||||||
stringToSymlinkType,
|
stringToSymlinkType,
|
||||||
toUnixTimestamp,
|
toUnixTimestamp,
|
||||||
|
validateBufferArray,
|
||||||
validateOffsetLengthRead,
|
validateOffsetLengthRead,
|
||||||
validateOffsetLengthWrite,
|
validateOffsetLengthWrite,
|
||||||
validatePath,
|
validatePath,
|
||||||
@ -142,19 +143,6 @@ function maybeCallback(cb) {
|
|||||||
throw new ERR_INVALID_CALLBACK(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
|
// Ensure that callbacks run in the global context. Only use this function
|
||||||
// for callbacks that are passed to the binding layer, callbacks that are
|
// for callbacks that are passed to the binding layer, callbacks that are
|
||||||
// invoked from JS already run in the proper scope.
|
// invoked from JS already run in the proper scope.
|
||||||
@ -626,10 +614,7 @@ function writev(fd, buffers, position, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateInt32(fd, 'fd', 0);
|
validateInt32(fd, 'fd', 0);
|
||||||
|
validateBufferArray(buffers);
|
||||||
if (!isBuffersArray(buffers)) {
|
|
||||||
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
|
|
||||||
}
|
|
||||||
|
|
||||||
const req = new FSReqCallback();
|
const req = new FSReqCallback();
|
||||||
req.oncomplete = wrapper;
|
req.oncomplete = wrapper;
|
||||||
@ -647,15 +632,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs, {
|
|||||||
enumerable: false
|
enumerable: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// fs.writevSync(fd, buffers[, position]);
|
|
||||||
function writevSync(fd, buffers, position) {
|
function writevSync(fd, buffers, position) {
|
||||||
|
|
||||||
validateInt32(fd, 'fd', 0);
|
validateInt32(fd, 'fd', 0);
|
||||||
const ctx = {};
|
validateBufferArray(buffers);
|
||||||
|
|
||||||
if (!isBuffersArray(buffers)) {
|
const ctx = {};
|
||||||
throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof position !== 'number')
|
if (typeof position !== 'number')
|
||||||
position = null;
|
position = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user