[SHELL32] Expand .lnk working directory string before checking if it's valid (#7710)

Handles the case where SEE_MASK_DOENVSUBST will expand it later inside ShellExeute.

CORE-19987
This commit is contained in:
Whindmar Saksit 2025-02-09 20:07:17 +01:00 committed by GitHub
parent 364d6e0346
commit e4216bd015
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -216,6 +216,22 @@ static LPWSTR __inline strdupW(LPCWSTR src)
return dest;
}
static BOOL PathEnvSubstIsDirectory(LPCWSTR pszPath)
{
// Note: Don't call SHExpandEnvironmentStringsW here, we need the required length
WCHAR szStack[MAX_PATH];
DWORD cch = ExpandEnvironmentStringsW(pszPath, szStack, _countof(szStack));
if (cch <= _countof(szStack))
return cch && PathIsDirectory(szStack);
PWSTR szHeap = (PWSTR)SHAlloc(cch);
if (!szHeap)
return FALSE;
BOOL bResult = ExpandEnvironmentStringsW(pszPath, szHeap, cch) && PathIsDirectory(szHeap);
SHFree(szHeap);
return bResult;
}
// TODO: Use it for constructor & destructor too
VOID CShellLink::Reset()
{
@ -2667,7 +2683,7 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
sei.nShow = lpici->nShow; // Allow invoker to override .lnk show mode
// Use the invoker specified working directory if the link did not specify one
if (StrIsNullOrEmpty(sei.lpDirectory) || !PathIsDirectoryW(sei.lpDirectory))
if (StrIsNullOrEmpty(sei.lpDirectory) || !PathEnvSubstIsDirectory(sei.lpDirectory))
{
LPCSTR pszDirA = lpici->lpDirectory;
if (unicode && !StrIsNullOrEmpty(iciex->lpDirectoryW))