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 <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
aduh95 authored and ruyadorno committed Mar 24, 2021
1 parent aa529b7 commit 3452618
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 3452618

Please sign in to comment.