cooked: properly tear down popups when we fail to parse user input (#20779)

Throwing an exception all the way out of COOKED_READ_DATA::Read is
deleterious for the health of the application. We fail to unbind the
waiter and may leave a dangling pointer around for some applications
(and for some NPC security researchers to think provides an EoP, but
does not.)

This also moves us away from std::stoi in the history pop-up path
entirely.

(cherry picked from commit 099afa48ed)
Service-Card-Id: PVTI_lADOAF3p4s4BlIihzg_QiVQ
Service-Version: 1.26
This commit is contained in:
Dustin L. Howett
2026-10-07 18:17:13 -05:00
committed by Dustin L. Howett
parent 53d40be00e
commit 1d95375cfd

View File

@@ -1439,6 +1439,7 @@ void COOKED_READ_DATA::_popupsDone()
}
void COOKED_READ_DATA::_popupHandleInput(wchar_t wch, uint16_t vkey, DWORD modifiers)
try
{
if (_popups.empty())
{
@@ -1465,6 +1466,11 @@ void COOKED_READ_DATA::_popupHandleInput(wchar_t wch, uint16_t vkey, DWORD modif
break;
}
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
_popupsDone();
}
void COOKED_READ_DATA::_popupHandleCopyToCharInput(Popup& /*popup*/, const wchar_t wch, const uint16_t vkey, const DWORD /*modifiers*/)
{
@@ -1528,8 +1534,10 @@ void COOKED_READ_DATA::_popupHandleCommandNumberInput(Popup& popup, const wchar_
{
if (wch == UNICODE_CARRIAGERETURN)
{
popup.commandNumber.buffer[popup.commandNumber.bufferSize++] = L'\0';
_replace(_history->RetrieveNth(std::stoi(popup.commandNumber.buffer.data())));
if (const auto commandNumber{ til::parse_signed<CommandHistory::Index>(std::wstring_view{ popup.commandNumber.buffer.data(), popup.commandNumber.bufferSize }, 10) })
{
_replace(_history->RetrieveNth(*commandNumber));
}
_popupsDone();
}
else if (wch >= L'0' && wch <= L'9')