[DEVMGR] Fix some bugs spotted by Thomas Faber in PR #5775 (#5790)

- Fix TCHAR/WCHAR mis-usage,
- Fix as a result, a buffer overflow (GlobalAlloc takes the size in
  bytes, but a number of characters was passed to it instead).
- Remove usage of unsafe string function. Now the item text is directly
  retrieved within the allocated buffer.
This commit is contained in:
Hermès Bélusca-Maïto 2023-10-12 15:34:06 +02:00
parent 7fb91d98f9
commit b4b1c5b9aa
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -413,7 +413,7 @@ DriverDetailsDlgProc(IN HWND hwndDlg,
pnmv->iItem,
pnmv->iSubItem,
szDriverPath,
MAX_PATH);
_countof(szDriverPath));
UpdateDriverVersionInfoDetails(hwndDlg,
szDriverPath);
@ -1944,16 +1944,11 @@ AdvProcDetailsDlgProc(IN HWND hwndDlg,
if (nSelectedId < 0 || nSelectedItems <= 0)
break;
TCHAR szItemName[MAX_PATH];
HGLOBAL hGlobal;
LPWSTR pszBuffer;
SIZE_T cchSize = MAX_PATH + 1;
ListView_GetItemText(hwndListView,
nSelectedId, 0,
szItemName,
_countof(szItemName));
hGlobal = GlobalAlloc(GHND, MAX_PATH);
hGlobal = GlobalAlloc(GHND, cchSize * sizeof(WCHAR));
if (!hGlobal)
break;
pszBuffer = (LPWSTR)GlobalLock(hGlobal);
@ -1963,7 +1958,12 @@ AdvProcDetailsDlgProc(IN HWND hwndDlg,
break;
}
wsprintf(pszBuffer, L"%s", szItemName);
ListView_GetItemText(hwndListView,
nSelectedId, 0,
pszBuffer,
cchSize);
/* Ensure NULL-termination */
pszBuffer[cchSize - 1] = UNICODE_NULL;
GlobalUnlock(hGlobal);