Skip to content

Commit 3452618

Browse files
aduh95ruyadorno
authored andcommitted
tty: validate file descriptor to avoid int32 overflow
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]>
1 parent aa529b7 commit 3452618

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/tty.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const {
4040
let readline;
4141

4242
function isatty(fd) {
43-
return NumberIsInteger(fd) && fd >= 0 && isTTY(fd);
43+
return NumberIsInteger(fd) && fd >= 0 && fd <= 2147483647 &&
44+
isTTY(fd);
4445
}
4546

4647
function ReadStream(fd, options) {

test/pseudo-tty/test-tty-isatty.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ strictEqual(isatty(2), true, 'stderr reported to not be a tty, but it is');
1010

1111
strictEqual(isatty(-1), false, '-1 reported to be a tty, but it is not');
1212
strictEqual(isatty(55555), false, '55555 reported to be a tty, but it is not');
13+
strictEqual(isatty(2 ** 31), false, '2^31 reported to be a tty, but it is not');
1314
strictEqual(isatty(1.1), false, '1.1 reported to be a tty, but it is not');
1415
strictEqual(isatty('1'), false, '\'1\' reported to be a tty, but it is not');
1516
strictEqual(isatty({}), false, '{} reported to be a tty, but it is not');

0 commit comments

Comments
 (0)