Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix crash when terminal is reset#6777

Merged
adityapatwardhan merged 3 commits intoPowerShell:masterfrom
SteveL-MSFT:term-reset
May 8, 2018
Merged

Fix crash when terminal is reset#6777
adityapatwardhan merged 3 commits intoPowerShell:masterfrom
SteveL-MSFT:term-reset

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Apr 30, 2018

PR Summary

When terminal is reset, the state of the string buffer is wrong so the built-in readline code tries to insert a character beyond the length of the buffer and thus crashes. Fix is to check if the index is greater than the size of the buffer and set it to the end of the buffer. Validated manually.

Fix #6776

PR Checklist

if (!insertMode) // then overwrite mode
if (!insertMode && s != "") // then overwrite mode
{
s = s.Remove(index, 1);
Copy link
Member

Choose a reason for hiding this comment

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

When it's the overwrite mode, index could be out of range here too, right?
And, if we check index here, it seems no reason to keep && s != "".

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, move check up

s = s.Remove(index, 1);
}

if (index > s.Length)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be helpful to have a comment explain when index > s.Length would happen.

// Modify string
if (!insertMode) // then overwrite mode
{
s = s.Remove(index, 1);
Copy link
Member

Choose a reason for hiding this comment

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

When index == s.Length, this line will throw. The if check probably should be updated to if (!insertMode && index < s.Length)

@adityapatwardhan adityapatwardhan merged commit 7931602 into PowerShell:master May 8, 2018
@SteveL-MSFT SteveL-MSFT mentioned this pull request May 23, 2018
@SteveL-MSFT SteveL-MSFT deleted the term-reset branch October 26, 2018 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Soft reset on plus cursor key input causes crash macOS

4 participants