Fix stack buffer overrun for 512 character window titles

Size the buffer from the converted length instead of fixed 512 size.
This commit is contained in:
WarmUpTill
2026-11-17 21:15:47 +01:00
parent b7bf68615d
commit f35827de0a
2 changed files with 9 additions and 8 deletions

View File

@@ -194,9 +194,11 @@ static std::vector<HWND> getHWNDfromTitle(const std::string &title)
HWND hwnd = nullptr;
HWND hPrevWnd = nullptr;
std::vector<HWND> hwnds;
wchar_t wTitle[512];
os_utf8_to_wcs(title.c_str(), 0, wTitle, 512);
while ((hwnd = FindWindowEx(NULL, hPrevWnd, NULL, wTitle)) != nullptr) {
size_t len = os_utf8_to_wcs(title.c_str(), 0, nullptr, 0);
std::wstring wTitle(len, L'\0');
os_utf8_to_wcs(title.c_str(), 0, wTitle.data(), len + 1);
while ((hwnd = FindWindowEx(NULL, hPrevWnd, NULL, wTitle.c_str())) !=
nullptr) {
if (windowIsValid(hwnd)) {
hwnds.emplace_back(hwnd);
}