Skip to content

Commit 249fe2a

Browse files
authored
Fix a crash when disabling the ASB (#17748)
`ProcessString` may delete the ASB and cause a dangling screen info pointer. As such, we must avoid using the pointer after the call. Closes #17709 ## Validation Steps Performed I couldn't repro the issue.
1 parent 408f3e2 commit 249fe2a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/host/_stream.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ void WriteCharsVT(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str)
336336
{
337337
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
338338
auto& stateMachine = screenInfo.GetStateMachine();
339+
// If the given screenInfo is the alternate screen buffer, disabling the alternate screen buffer in this
340+
// VT payload will cause the pointer to be invalidated. We thus need to get all the information we need now.
341+
const auto disableNewlineTranslation = WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN);
339342
// When switch between the main and alt-buffer SCREEN_INFORMATION::GetActiveBuffer()
340343
// may change, so get the VtIo reference now, just in case.
341344
auto writer = gci.GetVtWriterForBuffer(&screenInfo);
@@ -350,7 +353,7 @@ void WriteCharsVT(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str)
350353
// DISABLE_NEWLINE_AUTO_RETURN not being set is equivalent to a LF -> CRLF translation.
351354
const auto write = [&](size_t beg, size_t end) {
352355
const auto chunk = til::safe_slice_abs(str, beg, end);
353-
if (WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN))
356+
if (disableNewlineTranslation)
354357
{
355358
writer.WriteUTF16(chunk);
356359
}

0 commit comments

Comments
 (0)