comdlg32: Fix NULL lpstrFile uses in FILEDLG95_OnOpen.

This commit is contained in:
Bruno Jesus 2012-06-15 00:51:34 -03:00 committed by Alexandre Julliard
parent 6cc9968125
commit 8c5cf7e25f
2 changed files with 117 additions and 7 deletions

View file

@ -2684,16 +2684,20 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
}
else
{
LPSTR lpszTemp;
LPOPENFILENAMEA ofn = (LPOPENFILENAMEA)fodInfos->ofnInfos;
LPSTR lpszTemp;
CHAR tempFileA[MAX_PATH];
/* avoid using fodInfos->ofnInfos->lpstrFile since it can be NULL */
WideCharToMultiByte(CP_ACP, 0, lpstrPathAndFile, -1,
tempFileA, sizeof(tempFileA), NULL, NULL);
/* set filename offset */
lpszTemp = PathFindFileNameA(ofn->lpstrFile);
fodInfos->ofnInfos->nFileOffset = (lpszTemp - ofn->lpstrFile);
lpszTemp = PathFindFileNameA(tempFileA);
fodInfos->ofnInfos->nFileOffset = (lpszTemp - tempFileA);
/* set extension offset */
lpszTemp = PathFindExtensionA(ofn->lpstrFile);
fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? (lpszTemp - ofn->lpstrFile) + 1 : 0;
lpszTemp = PathFindExtensionA(tempFileA);
fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? (lpszTemp - tempFileA) + 1 : 0;
}
/* set the lpstrFileTitle */
@ -2746,7 +2750,8 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)
size += 1;
/* return needed size in first two bytes of lpstrFile */
*(WORD *)fodInfos->ofnInfos->lpstrFile = size;
if(fodInfos->ofnInfos->lpstrFile)
*(WORD *)fodInfos->ofnInfos->lpstrFile = size;
FILEDLG95_Clean(hwnd);
ret = EndDialog(hwnd, FALSE);
COMDLG32_SetCommDlgExtendedError(FNERR_BUFFERTOOSMALL);

View file

@ -1134,6 +1134,110 @@ static void test_extension(void)
#undef ARRAY_SIZE
static BOOL WINAPI test_null_enum(HWND hwnd, LPARAM lParam)
{
/* Find the textbox and send a filename so IDOK will work.
If the file textbox is empty IDOK will be ignored */
CHAR className[20];
if(GetClassNameA(hwnd, className, sizeof(className)) > 0 && !strcmp("Edit",className))
{
SetWindowText(hwnd, "testfile");
return FALSE; /* break window enumeration */
}
return TRUE;
}
static UINT_PTR WINAPI test_null_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND parent = GetParent( dlg);
if( msg == WM_NOTIFY) {
SetTimer( dlg, 0, 100, 0);
SetTimer( dlg, 1, 1000, 0);
EnumChildWindows( parent, test_null_enum, 0);
}
if( msg == WM_TIMER) {
if(!wParam)
PostMessage( parent, WM_COMMAND, IDOK, 0);
else {
/* the dialog did not close automatically */
KillTimer( dlg, 0);
PostMessage( parent, WM_COMMAND, IDCANCEL, 0);
}
}
return FALSE;
}
static void test_null_filename(void)
{
OPENFILENAMEA ofnA = {0};
OPENFILENAMEW ofnW = {0};
WCHAR filterW[] = {'t','e','x','t','\0','*','.','t','x','t','\0',
'A','l','l','\0','*','\0','\0'};
DWORD ret;
ofnA.lStructSize = sizeof(ofnA);
ofnA.lpstrFile = NULL;
ofnA.nMaxFile = 0;
ofnA.nFileOffset = 0xdead;
ofnA.nFileExtension = 0xbeef;
ofnA.lpfnHook = test_null_wndproc;
ofnA.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
ofnA.hInstance = GetModuleHandleA(NULL);
ofnA.lpstrFilter = "text\0*.txt\0All\0*\0\0";
ofnA.lpstrDefExt = NULL;
ret = GetOpenFileNameA(&ofnA);
todo_wine ok(ret, "GetOpenFileNameA returned %#x\n", ret);
ret = CommDlgExtendedError();
todo_wine ok(!ret, "CommDlgExtendedError returned %#x, should be 0\n", ret);
todo_wine ok(ofnA.nFileOffset != 0xdead, "ofnA.nFileOffset is 0xdead\n");
todo_wine ok(ofnA.nFileExtension != 0xbeef, "ofnA.nFileExtension is 0xbeef\n");
ofnA.lpstrFile = NULL;
ofnA.nMaxFile = 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
ofnA.nFileOffset = 0xdead;
ofnA.nFileExtension = 0xbeef;
ret = GetOpenFileNameA(&ofnA);
ok(ret, "GetOpenFileNameA returned %#x\n", ret);
ret = CommDlgExtendedError();
ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
ok(ofnA.nFileOffset != 0xdead, "ofnA.nFileOffset is 0xdead\n");
ok(ofnA.nFileExtension == 0, "ofnA.nFileExtension is 0x%x, should be 0\n", ofnA.nFileExtension);
/* unicode tests */
ofnW.lStructSize = sizeof(ofnW);
ofnW.lpstrFile = NULL;
ofnW.nMaxFile = 0;
ofnW.nFileOffset = 0xdead;
ofnW.nFileExtension = 0xbeef;
ofnW.lpfnHook = test_null_wndproc;
ofnW.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
ofnW.hInstance = GetModuleHandleW(NULL);
ofnW.lpstrFilter = filterW;
ofnW.lpstrDefExt = NULL;
ret = GetOpenFileNameW(&ofnW);
todo_wine ok(ret, "GetOpenFileNameW returned %#x\n", ret);
ret = CommDlgExtendedError();
todo_wine ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
todo_wine ok(ofnW.nFileOffset != 0xdead, "ofnW.nFileOffset is 0xdead\n");
todo_wine ok(ofnW.nFileExtension != 0xbeef, "ofnW.nFileExtension is 0xbeef\n");
ofnW.lpstrFile = NULL;
ofnW.nMaxFile = 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
ofnW.nFileOffset = 0xdead;
ofnW.nFileExtension = 0xbeef;
ret = GetOpenFileNameW(&ofnW);
ok(ret, "GetOpenFileNameA returned %#x\n", ret);
ret = CommDlgExtendedError();
ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
ok(ofnW.nFileOffset != 0xdead, "ofnW.nFileOffset is 0xdead\n");
ok(ofnW.nFileExtension == 0, "ofnW.nFileExtension is 0x%x, should be 0\n", ofnW.nFileExtension);
}
START_TEST(filedlg)
{
test_DialogCancel();
@ -1146,4 +1250,5 @@ START_TEST(filedlg)
test_mru();
if( resizesupported) test_resizable2();
test_extension();
test_null_filename();
}