https://git.reactos.org/?p=reactos.git;a=commitdiff;h=55a5d7a177b9fc38a506f…
commit 55a5d7a177b9fc38a506f8fa57a82870321ca8d9
Author: Whindmar Saksit <whindsaks(a)proton.me>
AuthorDate: Mon Jan 8 17:02:59 2024 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Jan 8 17:02:59 2024 +0100
[SHELL32] RegFolder must correctly handle GetDisplayNameOf parsing paths (#6265)
---
dll/win32/shell32/folders/CRegFolder.cpp | 40 +++++++++++++++++++++++++-------
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git a/dll/win32/shell32/folders/CRegFolder.cpp
b/dll/win32/shell32/folders/CRegFolder.cpp
index 16b0b7325e2..5b2d513569b 100644
--- a/dll/win32/shell32/folders/CRegFolder.cpp
+++ b/dll/win32/shell32/folders/CRegFolder.cpp
@@ -641,7 +641,8 @@ HRESULT WINAPI CRegFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl,
DWORD dwFlags,
}
/* Allocate the buffer for the result */
- LPWSTR pszPath = (LPWSTR)CoTaskMemAlloc((MAX_PATH + 1) * sizeof(WCHAR));
+ SIZE_T cchPath = MAX_PATH + 1;
+ LPWSTR pszPath = (LPWSTR)CoTaskMemAlloc(cchPath * sizeof(WCHAR));
if (!pszPath)
return E_OUTOFMEMORY;
@@ -649,18 +650,41 @@ HRESULT WINAPI CRegFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl,
DWORD dwFlags,
if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING)
{
- wcscpy(pszPath, m_rootPath);
- PWCHAR pItemName = &pszPath[wcslen(pszPath)];
+ SIZE_T pathlen = 0;
+ PWCHAR pItemName = pszPath; // GET_SHGDN_RELATION(dwFlags) == SHGDN_INFOLDER
+ if (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)
+ {
+ hr = StringCchCopyW(pszPath, cchPath, m_rootPath);
+ if (SUCCEEDED(hr))
+ {
+ pathlen = wcslen(pszPath);
+ pItemName = &pszPath[pathlen];
+ if (pathlen)
+ {
+ if (++pathlen < cchPath)
+ *pItemName++ = L'\\';
+ else
+ hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
+ }
+ }
+ }
- /* parsing name like ::{...} */
- pItemName[0] = ':';
- pItemName[1] = ':';
- SHELL32_GUIDToStringW (*clsid, &pItemName[2]);
+ if (SUCCEEDED(hr) && pathlen + 2 + 38 + 1 < cchPath)
+ {
+ /* parsing name like ::{...} */
+ pItemName[0] = L':';
+ pItemName[1] = L':';
+ SHELL32_GUIDToStringW(*clsid, &pItemName[2]);
+ }
+ else
+ {
+ hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
+ }
}
else
{
/* user friendly name */
- if (!HCR_GetClassNameW (*clsid, pszPath, MAX_PATH))
+ if (!HCR_GetClassNameW(*clsid, pszPath, cchPath))
hr = E_FAIL;
}