Skip to content

Commit

Permalink
tty: validate file descriptor to avoid int32 overflow
Browse files Browse the repository at this point in the history
Fixes: #37805

PR-URL: #37809
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
aduh95 authored and targos committed May 1, 2021
1 parent f533488 commit d89d55a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const {
let readline;

function isatty(fd) {
return NumberIsInteger(fd) && fd >= 0 && isTTY(fd);
return NumberIsInteger(fd) && fd >= 0 && fd <= 2147483647 &&
isTTY(fd);
}

function ReadStream(fd, options) {
Expand Down
1 change: 1 addition & 0 deletions test/pseudo-tty/test-tty-isatty.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ strictEqual(isatty(2), true, 'stderr reported to not be a tty, but it is');

strictEqual(isatty(-1), false, '-1 reported to be a tty, but it is not');
strictEqual(isatty(55555), false, '55555 reported to be a tty, but it is not');
strictEqual(isatty(2 ** 31), false, '2^31 reported to be a tty, but it is not');
strictEqual(isatty(1.1), false, '1.1 reported to be a tty, but it is not');
strictEqual(isatty('1'), false, '\'1\' reported to be a tty, but it is not');
strictEqual(isatty({}), false, '{} reported to be a tty, but it is not');
Expand Down

0 comments on commit d89d55a

Please sign in to comment.