Skip to content

Commit

Permalink
lib: fix fs.read when passing null value
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Mar 26, 2020
1 parent f0a33d9 commit e8daf89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,12 @@ function read(fd, buffer, offset, length, position, callback) {
callback = offset;
}

buffer = options.buffer || Buffer.alloc(16384);
offset = options.offset || 0;
length = options.length || buffer.length;
position = options.position;
({
buffer = Buffer.alloc(16384),
offset = 0,
length = buffer.length,
position
} = options);
}

validateBuffer(buffer);
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ assert.throws(
}
);

['buffer', 'offset', 'length'].forEach((option) =>
assert.throws(
() => fs.read(fd, {
[option]: null
}),
`not throws when options.${option} is null`
));

assert.throws(
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),
{
Expand Down

0 comments on commit e8daf89

Please sign in to comment.