From 52c70bd23282a0e2f0bd949ee6ea46b743dc4e2e Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 27 Apr 2016 16:39:23 +0200 Subject: [PATCH] Added patch to postpone setting lpstrFileTitle to work around application bugs. --- ...e-setting-ofn-lpstrFileTitle-to-work.patch | 74 +++++++++++++++++++ patches/comdlg32-lpstrFileTitle/definition | 2 + patches/patchinstall.sh | 20 +++++ 3 files changed, 96 insertions(+) create mode 100644 patches/comdlg32-lpstrFileTitle/0001-comdlg32-Postpone-setting-ofn-lpstrFileTitle-to-work.patch create mode 100644 patches/comdlg32-lpstrFileTitle/definition diff --git a/patches/comdlg32-lpstrFileTitle/0001-comdlg32-Postpone-setting-ofn-lpstrFileTitle-to-work.patch b/patches/comdlg32-lpstrFileTitle/0001-comdlg32-Postpone-setting-ofn-lpstrFileTitle-to-work.patch new file mode 100644 index 00000000..19c4ea98 --- /dev/null +++ b/patches/comdlg32-lpstrFileTitle/0001-comdlg32-Postpone-setting-ofn-lpstrFileTitle-to-work.patch @@ -0,0 +1,74 @@ +From 022ab9291e3d8c324c7c2dacbfb0b23e234fb4ae Mon Sep 17 00:00:00 2001 +From: Dmitry Timoshkov +Date: Tue, 26 Apr 2016 18:28:21 +0800 +Subject: 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. +--- + dlls/comdlg32/filedlg.c | 31 ++++++++++++++----------------- + 1 file changed, 14 insertions(+), 17 deletions(-) + +diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c +index 1453396..6a6a093 100644 +--- a/dlls/comdlg32/filedlg.c ++++ b/dlls/comdlg32/filedlg.c +@@ -463,6 +463,13 @@ static BOOL GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType) + ret = FALSE; + } + ++ /* set the lpstrFileTitle */ ++ if (ret && ofn->lpstrFile && ofn->lpstrFileTitle) ++ { ++ LPSTR lpstrFileTitle = PathFindFileNameA(ofn->lpstrFile); ++ lstrcpynA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle); ++ } ++ + if (lpstrSavDir) + { + SetCurrentDirectoryA(lpstrSavDir); +@@ -555,6 +562,13 @@ static BOOL GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType) + ret = FALSE; + } + ++ /* set the lpstrFileTitle */ ++ if (ret && ofn->lpstrFile && ofn->lpstrFileTitle) ++ { ++ LPWSTR lpstrFileTitle = PathFindFileNameW(ofn->lpstrFile); ++ lstrcpynW(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle); ++ } ++ + if (lpstrSavDir) + { + SetCurrentDirectoryW(lpstrSavDir); +@@ -2735,23 +2749,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) + { +-- +2.8.0 + diff --git a/patches/comdlg32-lpstrFileTitle/definition b/patches/comdlg32-lpstrFileTitle/definition new file mode 100644 index 00000000..2c23a875 --- /dev/null +++ b/patches/comdlg32-lpstrFileTitle/definition @@ -0,0 +1,2 @@ +Fixes: [38400] Postpone setting lpstrFileTitle in GetSaveFileNameW +Fixes: [35200] Postpone setting lpstrFileTitle in GetSaveFileNameA diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index c992eede..40c556b9 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -97,6 +97,7 @@ patch_enable_all () enable_comctl32_Button_Theming="$1" enable_comctl32_PROPSHEET_InsertPage="$1" enable_comctl32_TTM_ADDTOOLW="$1" + enable_comdlg32_lpstrFileTitle="$1" enable_configure_Absolute_RPATH="$1" enable_crypt32_CMS_Certificates="$1" enable_crypt32_CryptUnprotectMemory="$1" @@ -461,6 +462,9 @@ patch_enable () comctl32-TTM_ADDTOOLW) enable_comctl32_TTM_ADDTOOLW="$2" ;; + comdlg32-lpstrFileTitle) + enable_comdlg32_lpstrFileTitle="$2" + ;; configure-Absolute_RPATH) enable_configure_Absolute_RPATH="$2" ;; @@ -2794,6 +2798,22 @@ if test "$enable_comctl32_TTM_ADDTOOLW" -eq 1; then ) >> "$patchlist" fi +# Patchset comdlg32-lpstrFileTitle +# | +# | This patchset fixes the following Wine bugs: +# | * [#38400] Postpone setting lpstrFileTitle in GetSaveFileNameW +# | * [#35200] Postpone setting lpstrFileTitle in GetSaveFileNameA +# | +# | Modified files: +# | * dlls/comdlg32/filedlg.c +# | +if test "$enable_comdlg32_lpstrFileTitle" -eq 1; then + patch_apply comdlg32-lpstrFileTitle/0001-comdlg32-Postpone-setting-ofn-lpstrFileTitle-to-work.patch + ( + echo '+ { "Dmitry Timoshkov", "comdlg32: Postpone setting ofn->lpstrFileTitle to work around an application bug.", 1 },'; + ) >> "$patchlist" +fi + # Patchset configure-Absolute_RPATH # | # | This patchset fixes the following Wine bugs: