Commit 921aaa6f authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Vitaly Lipatov

comdlg32: Postpone setting ofn->lpstrFileTitle to work around an application bug.

An application in the bug 38400 passes a not initialized ofn->lpstrFileTitle to GetSaveFileNameW(). Basically ofn->lpstrFileTitle points to the stack approximately 428 bytes above the current stack pointer, and since Wine's GetSaveFileNameW() uses more than 4096 bytes one of internal stack frames is guaranteed to be trashed after copying file name to ofn->lpstrFileTitle.
parent 2f949f2e
......@@ -561,6 +561,23 @@ static BOOL GetFileDialog95(FileOpenDlgInfos *info, UINT dlg_type)
ret = FALSE;
}
/* set the lpstrFileTitle */
if (ret && info->ofnInfos->lpstrFile && info->ofnInfos->lpstrFileTitle)
{
if (info->unicode)
{
LPOPENFILENAMEW ofn = info->ofnInfos;
WCHAR *file_title = PathFindFileNameW(ofn->lpstrFile);
lstrcpynW(ofn->lpstrFileTitle, file_title, ofn->nMaxFileTitle);
}
else
{
LPOPENFILENAMEA ofn = (LPOPENFILENAMEA)info->ofnInfos;
char *file_title = PathFindFileNameA(ofn->lpstrFile);
lstrcpynA(ofn->lpstrFileTitle, file_title, ofn->nMaxFileTitle);
}
}
if (current_dir)
{
SetCurrentDirectoryW(current_dir);
......@@ -2871,23 +2888,6 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? (lpszTemp - tempFileA) + 1 : 0;
}
/* set the lpstrFileTitle */
if(fodInfos->ofnInfos->lpstrFileTitle)
{
LPWSTR lpstrFileTitle = PathFindFileNameW(lpstrPathAndFile);
if(fodInfos->unicode)
{
LPOPENFILENAMEW ofn = fodInfos->ofnInfos;
lstrcpynW(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
}
else
{
LPOPENFILENAMEA ofn = (LPOPENFILENAMEA)fodInfos->ofnInfos;
WideCharToMultiByte(CP_ACP, 0, lpstrFileTitle, -1,
ofn->lpstrFileTitle, ofn->nMaxFileTitle, NULL, NULL);
}
}
/* copy currently selected filter to lpstrCustomFilter */
if (fodInfos->ofnInfos->lpstrCustomFilter)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment