Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Cannot read properties of null for setRawMode #41335

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ObjectSetPrototypeOf(ReadStream, net.Socket);

ReadStream.prototype.setRawMode = function(flag) {
flag = !!flag;
const err = this._handle.setRawMode(flag);
const err = this._handle && this._handle.setRawMode(flag);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be covered by a test. Also, is it correct that this function does not fail if this._handle == null?

Copy link
Author

@asaid-0 asaid-0 Dec 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review
I think it's safe as long as this._handle would be null if this function is called when using the terminal.
also, I found this check in readline interface:

if (typeof this.input.setRawMode === 'function') {
this.input.setRawMode(mode);

I have covered this issue by a test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tniessen What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const err = this._handle && this._handle.setRawMode(flag);
const err = this._handle?.setRawMode(flag);

if (err) {
this.emit('error', errors.errnoException(err, 'setRawMode'));
return this;
Expand Down