From 1d95375cfdf3f59be038418e103a4d0740834c19 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Wed, 7 Oct 2026 18:17:13 -0500 Subject: [PATCH] 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 099afa48ed0ae49e233a663c30a41dee09050990) Service-Card-Id: PVTI_lADOAF3p4s4BlIihzg_QiVQ Service-Version: 1.26 --- src/host/readDataCooked.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/host/readDataCooked.cpp b/src/host/readDataCooked.cpp index ee862a03ae..c29e51ba83 100644 --- a/src/host/readDataCooked.cpp +++ b/src/host/readDataCooked.cpp @@ -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(std::wstring_view{ popup.commandNumber.buffer.data(), popup.commandNumber.bufferSize }, 10) }) + { + _replace(_history->RetrieveNth(*commandNumber)); + } _popupsDone(); } else if (wch >= L'0' && wch <= L'9')