Skip to content

Commit

Permalink
Added null check before rendering a string from the terminal connecti…
Browse files Browse the repository at this point in the history
…on (#14515)

Watson reports show that Visual Studio terminal attempts to render a string that is null causing the renderer to crash.

More specifically, we see "NULL_POINTER_WRITE_c0000005_PublicTerminalCore.dll!TextBuffer::WriteLine" with the following stack:
PublicTerminalCore!TextBuffer::WriteLine+0x1da
PublicTerminalCore!TextBuffer::Write+0x191
PublicTerminalCore!Microsoft::Terminal::Core::Terminal::_WriteBuffer+0x1d3
PublicTerminalCore!Microsoft::Terminal::Core::Terminal::PrintString+0x9
PublicTerminalCore!TerminalDispatch::PrintString+0x22
PublicTerminalCore!Microsoft::Console::VirtualTerminal::OutputStateMachineEngine::ActionPrintString+0x42
PublicTerminalCore!Microsoft::Console::VirtualTerminal::StateMachine::ProcessString+0x123
PublicTerminalCore!TerminalSendOutput+0x68
Microsoft_DotNet_MSBuildSdkResolver!DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, System.String)+0x8f
Microsoft_Terminal_Wpf!Microsoft.Terminal.Wpf.TerminalContainer.Connection_TerminalOutput(System.Object, Microsoft.Terminal.Wpf.TerminalOutputEventArgs)+0x20
Microsoft_VisualStudio_Terminal_Implementation!Microsoft.VisualStudio.Terminal.TerminalWindowBase+<>c__DisplayClass59_0+<<BeginProcessingPtyData>b__0>d.MoveNext()+0x55f

Internal bug: [Bug 1614709](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1614709): [Watson] crash64: NULL_POINTER_WRITE_c0000005_PublicTerminalCore.dll!TextBuffer::WriteLine

Added a null check before PInvoking TerminalSendOutput.

Validated locally that the check prevents null strings from rendering.

(cherry picked from commit 79c47f6)
Service-Card-Id: 87204854
Service-Version: 1.16
  • Loading branch information
javierdlg authored and DHowett committed Dec 12, 2022
1 parent b73718a commit a23423a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cascadia/WpfTerminalControl/TerminalContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,12 @@ private void MouseMoveHandler(int wParam, int lParam)

private void Connection_TerminalOutput(object sender, TerminalOutputEventArgs e)
{
if (this.terminal != IntPtr.Zero)
if (this.terminal == IntPtr.Zero || string.IsNullOrEmpty(e.Data))
{
NativeMethods.TerminalSendOutput(this.terminal, e.Data);
return;
}

NativeMethods.TerminalSendOutput(this.terminal, e.Data);
}

private void OnScroll(int viewTop, int viewHeight, int bufferSize)
Expand Down

0 comments on commit a23423a

Please sign in to comment.