From bbf2cce16041e90d621a1f5889ea1bd760e21a0e Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Fri, 20 Jul 2012 08:33:08 +0200 Subject: [PATCH] comdlg32: Do not modify dialog resource directly. --- dlls/comdlg32/filedlg.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c index 3e7ee4f2f4e..c49ed201a46 100644 --- a/dlls/comdlg32/filedlg.c +++ b/dlls/comdlg32/filedlg.c @@ -252,7 +252,9 @@ static BOOL GetFileName95(FileOpenDlgInfos *fodInfos) { LRESULT lRes; - LPVOID template; + LPCVOID origTemplate; + DWORD dwSize; + LPDLGTEMPLATEW template; HRSRC hRes; HANDLE hDlgTmpl = 0; HRESULT hr; @@ -271,12 +273,19 @@ static BOOL GetFileName95(FileOpenDlgInfos *fodInfos) COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; } - if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hRes )) || - !(template = LockResource( hDlgTmpl ))) + if (!(dwSize = SizeofResource(COMDLG32_hInstance, hRes)) || + !(hDlgTmpl = LoadResource(COMDLG32_hInstance, hRes)) || + !(origTemplate = LockResource(hDlgTmpl))) { COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); return FALSE; } + if (!(template = HeapAlloc(GetProcessHeap(), 0, dwSize))) + { + COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE); + return FALSE; + } + memcpy(template, origTemplate, dwSize); /* msdn: explorer style dialogs permit sizing by default. * The OFN_ENABLESIZING flag is only needed when a hook or @@ -287,12 +296,12 @@ static BOOL GetFileName95(FileOpenDlgInfos *fodInfos) if (fodInfos->ofnInfos->Flags & OFN_ENABLESIZING) { - ((LPDLGTEMPLATEW)template)->style |= WS_SIZEBOX; + template->style |= WS_SIZEBOX; fodInfos->sizedlg.cx = fodInfos->sizedlg.cy = 0; fodInfos->initial_size.x = fodInfos->initial_size.y = 0; } else - ((LPDLGTEMPLATEW)template)->style &= ~WS_SIZEBOX; + template->style &= ~WS_SIZEBOX; /* old style hook messages */ @@ -322,6 +331,8 @@ static BOOL GetFileName95(FileOpenDlgInfos *fodInfos) if (SUCCEEDED(hr)) OleUninitialize(); + HeapFree(GetProcessHeap(), 0, template); + /* Unable to create the dialog */ if( lRes == -1) return FALSE;