Fix a lurking infinite loop in SHGetPathFromIDList.

This commit is contained in:
Michael Jung 2005-06-25 18:32:17 +00:00 committed by Alexandre Julliard
parent 41a9757654
commit 114975d937
1 changed files with 40 additions and 28 deletions

View File

@ -70,14 +70,26 @@ static const WCHAR wszDotShellClassInfo[] = {
* TRUE if returned non-NULL value. * TRUE if returned non-NULL value.
* FALSE otherwise. * FALSE otherwise.
*/ */
BOOL SHELL32_GetCustomFolderAttribute( static inline BOOL SHELL32_GetCustomFolderAttributeFromPath(
LPCITEMIDLIST pidl, LPCWSTR pwszHeading, LPCWSTR pwszAttribute, LPWSTR pwszFolderPath, LPCWSTR pwszHeading, LPCWSTR pwszAttribute,
LPWSTR pwszValue, DWORD cchValue) LPWSTR pwszValue, DWORD cchValue)
{ {
static const WCHAR wszDesktopIni[] = static const WCHAR wszDesktopIni[] =
{'d','e','s','k','t','o','p','.','i','n','i',0}; {'d','e','s','k','t','o','p','.','i','n','i',0};
static const WCHAR wszDefault[] = {0}; static const WCHAR wszDefault[] = {0};
PathAddBackslashW(pwszFolderPath);
PathAppendW(pwszFolderPath, wszDesktopIni);
return GetPrivateProfileStringW(pwszHeading, pwszAttribute, wszDefault,
pwszValue, cchValue, pwszFolderPath);
}
BOOL SHELL32_GetCustomFolderAttribute(
LPCITEMIDLIST pidl, LPCWSTR pwszHeading, LPCWSTR pwszAttribute,
LPWSTR pwszValue, DWORD cchValue)
{
DWORD dwAttrib = FILE_ATTRIBUTE_SYSTEM; DWORD dwAttrib = FILE_ATTRIBUTE_SYSTEM;
WCHAR wszFolderPath[MAX_PATH];
/* Hack around not having system attribute on non-Windows file systems */ /* Hack around not having system attribute on non-Windows file systems */
if (0) if (0)
@ -85,20 +97,15 @@ BOOL SHELL32_GetCustomFolderAttribute(
if (dwAttrib & FILE_ATTRIBUTE_SYSTEM) if (dwAttrib & FILE_ATTRIBUTE_SYSTEM)
{ {
DWORD ret; if (!SHGetPathFromIDListW(pidl, wszFolderPath))
WCHAR wszDesktopIniPath[MAX_PATH];
if (!SHGetPathFromIDListW(pidl, wszDesktopIniPath))
return FALSE; return FALSE;
PathAppendW(wszDesktopIniPath, wszDesktopIni);
ret = GetPrivateProfileStringW(pwszHeading, pwszAttribute, return SHELL32_GetCustomFolderAttributeFromPath(wszFolderPath, pwszHeading,
wszDefault, pwszValue, cchValue, wszDesktopIniPath); pwszAttribute, pwszValue, cchValue);
return ret;
} }
return FALSE; return FALSE;
} }
/*************************************************************************** /***************************************************************************
* GetNextElement (internal function) * GetNextElement (internal function)
* *
@ -277,13 +284,18 @@ HRESULT SHELL32_BindToChild (LPCITEMIDLIST pidlRoot,
/* file system folder */ /* file system folder */
CLSID clsidFolder = CLSID_ShellFSFolder; CLSID clsidFolder = CLSID_ShellFSFolder;
static const WCHAR wszCLSID[] = {'C','L','S','I','D',0}; static const WCHAR wszCLSID[] = {'C','L','S','I','D',0};
WCHAR wszCLSIDValue[CHARS_IN_GUID]; WCHAR wszCLSIDValue[CHARS_IN_GUID], wszFolderPath[MAX_PATH], *pwszPathTail = wszFolderPath;
LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
/* see if folder CLSID should be overridden by desktop.ini file */ /* see if folder CLSID should be overridden by desktop.ini file */
if (SHELL32_GetCustomFolderAttribute (pidlAbsolute, if (pathRoot) {
MultiByteToWideChar(CP_ACP, 0, pathRoot, -1, wszFolderPath, MAX_PATH);
pwszPathTail = PathAddBackslashW(wszFolderPath);
}
MultiByteToWideChar(CP_ACP, 0, _ILGetTextPointer(pidlChild), -1, pwszPathTail, MAX_PATH);
if (SHELL32_GetCustomFolderAttributeFromPath (wszFolderPath,
wszDotShellClassInfo, wszCLSID, wszCLSIDValue, CHARS_IN_GUID)) wszDotShellClassInfo, wszCLSID, wszCLSIDValue, CHARS_IN_GUID))
CLSIDFromString (wszCLSIDValue, &clsidFolder); CLSIDFromString (wszCLSIDValue, &clsidFolder);
ILFree (pidlAbsolute);
hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild,
&clsidFolder, &IID_IShellFolder, (LPVOID *)&pSF); &clsidFolder, &IID_IShellFolder, (LPVOID *)&pSF);
} }