tty: validate file descriptor to avoid int32 overflow

Fixes: https://github.com/nodejs/node/issues/37805

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Antoine du Hamel 2021-03-19 10:48:02 +01:00
parent 3bee6d8aad
commit 134fb5a8d0
2 changed files with 3 additions and 1 deletions

View File

@ -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) {

View File

@ -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');