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

Conversation

asaid-0
Copy link

@asaid-0 asaid-0 commented Dec 27, 2021

Fixes #41330

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. tty Issues and PRs related to the tty subsystem. labels Dec 27, 2021
@@ -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);

Comment on lines +8 to +12
const r = require('repl').start();

// Should not throw.
r.write('process.stdin.push(null)\n');
r.write('.exit\n');
Copy link
Contributor

Choose a reason for hiding this comment

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

This test already passes with current version of Node.js, that means it's failing to replicate the issue at hand.

All fixes must have a test case which demonstrates the defect. The test should
fail before the change, and pass after the change.

@aduh95
Copy link
Contributor

aduh95 commented Aug 25, 2022

Superseded by #43803.

@aduh95 aduh95 closed this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. tty Issues and PRs related to the tty subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node in terminal window gives error - Cannot read property 'setRawMode' of null
4 participants