Skip to content

Commit

Permalink
fs: fix fs.read when passing null value
Browse files Browse the repository at this point in the history
PR-URL: #32479
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
  • Loading branch information
himself65 authored and addaleax committed Mar 30, 2020
1 parent 1fc19b0 commit b8b8e82
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 @@ -485,10 +485,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 b8b8e82

Please sign in to comment.