Skip to content

Commit 10d0f0d

Browse files
committed
tty: initialize winSize array with values
Assigning to a holey array in the native layer may crash if it has getters that throw. Refs: #54186 PR-URL: #54281 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent d415147 commit 10d0f0d

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/tty.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
'use strict';
2323

2424
const {
25-
Array,
2625
NumberIsInteger,
2726
ObjectSetPrototypeOf,
2827
} = primordials;
@@ -106,7 +105,7 @@ function WriteStream(fd) {
106105
// Ref: https://github.com/nodejs/node/pull/1771#issuecomment-119351671
107106
this._handle.setBlocking(true);
108107

109-
const winSize = new Array(2);
108+
const winSize = [0, 0];
110109
const err = this._handle.getWindowSize(winSize);
111110
if (!err) {
112111
this.columns = winSize[0];
@@ -126,7 +125,7 @@ WriteStream.prototype.hasColors = hasColors;
126125
WriteStream.prototype._refreshSize = function() {
127126
const oldCols = this.columns;
128127
const oldRows = this.rows;
129-
const winSize = new Array(2);
128+
const winSize = [0, 0];
130129
const err = this._handle.getWindowSize(winSize);
131130
if (err) {
132131
this.emit('error', new errors.ErrnoException(err, 'getWindowSize'));

0 commit comments

Comments
 (0)