From 7a6b00dc25880bd7e8515551b7c3fa7917776eaf Mon Sep 17 00:00:00 2001 From: Vijay Kiran Kamuju Date: Fri, 22 Feb 2019 14:25:59 +0100 Subject: [PATCH] user32: Add DlgDirList wildcard checks. Based on a patch from Christian Lupien. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=8226 Signed-off-by: Vijay Kiran Kamuju Signed-off-by: Alexandre Julliard --- dlls/comctl32/tests/listbox.c | 6 +++--- dlls/user32/dialog.c | 9 ++++++++- dlls/user32/tests/listbox.c | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c index de73ad2a56a..70e212892a4 100644 --- a/dlls/comctl32/tests/listbox.c +++ b/dlls/comctl32/tests/listbox.c @@ -1941,7 +1941,7 @@ static void test_listbox_dlgdir(void) strcpy(pathBuffer, "C:\\"); res = DlgDirListA(hWnd, pathBuffer, ID_TEST_LISTBOX, 0, DDL_DIRECTORY | DDL_EXCLUSIVE); ok(res, "DlgDirList failed to list C:\\ folders\n"); - todo_wine ok(!strcmp(pathBuffer, "*"), "DlgDirList set the invalid path spec '%s', expected '*'\n", pathBuffer); + ok(!strcmp(pathBuffer, "*"), "DlgDirList set the invalid path spec '%s', expected '*'\n", pathBuffer); strcpy(pathBuffer, "C:\\*"); res = DlgDirListA(hWnd, pathBuffer, ID_TEST_LISTBOX, 0, DDL_DIRECTORY | DDL_EXCLUSIVE); @@ -1952,8 +1952,8 @@ static void test_listbox_dlgdir(void) SetLastError(0xdeadbeef); strcpy(pathBuffer, "C:\\INVALID$$DIR"); res = DlgDirListA(hWnd, pathBuffer, ID_TEST_LISTBOX, 0, DDL_DIRECTORY | DDL_EXCLUSIVE); - todo_wine ok(!res, "DlgDirList should have failed with 0 but %d was returned\n", res); - todo_wine ok(GetLastError() == ERROR_NO_WILDCARD_CHARACTERS, + ok(!res, "DlgDirList should have failed with 0 but %d was returned\n", res); + ok(GetLastError() == ERROR_NO_WILDCARD_CHARACTERS, "GetLastError should return 0x589, got 0x%X\n",GetLastError()); DestroyWindow(hWnd); diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c index deaeb845565..88c2930c065 100644 --- a/dlls/user32/dialog.c +++ b/dlls/user32/dialog.c @@ -1821,6 +1821,7 @@ static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox, HWND hwnd; LPWSTR orig_spec = spec; WCHAR any[] = {'*','.','*',0}; + WCHAR star[] = {'*',0}; #define SENDMSG(msg,wparam,lparam) \ ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \ @@ -1829,10 +1830,16 @@ static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox, TRACE("%p %s %d %d %04x\n", hDlg, debugstr_w(spec), idLBox, idStatic, attrib ); /* If the path exists and is a directory, chdir to it */ - if (!spec || !spec[0] || SetCurrentDirectoryW( spec )) spec = any; + if (!spec || !spec[0] || SetCurrentDirectoryW( spec )) spec = star; else { WCHAR *p, *p2; + + if (!strchrW(spec, '*') && !strchrW(spec, '?')) + { + SetLastError(ERROR_NO_WILDCARD_CHARACTERS); + return FALSE; + } p = spec; if ((p2 = strchrW( p, ':' ))) p = p2 + 1; if ((p2 = strrchrW( p, '\\' ))) p = p2; diff --git a/dlls/user32/tests/listbox.c b/dlls/user32/tests/listbox.c index d15b18ac69a..8d8115131ef 100644 --- a/dlls/user32/tests/listbox.c +++ b/dlls/user32/tests/listbox.c @@ -1836,7 +1836,7 @@ static void test_listbox_dlgdir(void) strcpy(pathBuffer, "C:\\"); res = DlgDirListA(hWnd, pathBuffer, ID_TEST_LISTBOX, 0, DDL_DIRECTORY | DDL_EXCLUSIVE); ok(res || broken(!res) /* NT4/W2K */, "DlgDirList failed to list C:\\ folders\n"); - todo_wine ok(!strcmp(pathBuffer, "*") || broken(!res) /* NT4/W2K */, + ok(!strcmp(pathBuffer, "*") || broken(!res) /* NT4/W2K */, "DlgDirList set the invalid path spec '%s', expected '*'\n", pathBuffer); strcpy(pathBuffer, "C:\\*"); @@ -1849,8 +1849,8 @@ static void test_listbox_dlgdir(void) SetLastError(0xdeadbeef); strcpy(pathBuffer, "C:\\INVALID$$DIR"); res = DlgDirListA(hWnd, pathBuffer, ID_TEST_LISTBOX, 0, DDL_DIRECTORY | DDL_EXCLUSIVE); - todo_wine ok(!res, "DlgDirList should have failed with 0 but %d was returned\n", res); - todo_wine ok(GetLastError() == ERROR_NO_WILDCARD_CHARACTERS, + ok(!res, "DlgDirList should have failed with 0 but %d was returned\n", res); + ok(GetLastError() == ERROR_NO_WILDCARD_CHARACTERS, "GetLastError should return 0x589, got 0x%X\n",GetLastError()); DestroyWindow(hWnd);