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‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const{
4040
letreadline;
4141

4242
functionisatty(fd){
43-
returnNumberIsInteger(fd)&&fd>=0&&isTTY(fd);
43+
returnNumberIsInteger(fd)&&fd>=0&&fd<=2147483647&&
44+
isTTY(fd);
4445
}
4546

4647
functionReadStream(fd,options){

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

Lines changed: 1 addition & 0 deletions
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)