diff --git a/dlls/kernel/tests/file.c b/dlls/kernel/tests/file.c index 3a0ecc60a81..0ff985fb976 100644 --- a/dlls/kernel/tests/file.c +++ b/dlls/kernel/tests/file.c @@ -746,6 +746,26 @@ static void test_LockFile(void) DeleteFileA( filename ); } +void test_FindFirstFileA() +{ + HANDLE handle; + WIN32_FIND_DATAA search_results; + int err; + + handle = FindFirstFileA("C:",&search_results); + err = GetLastError(); + ok ( handle == INVALID_HANDLE_VALUE , "FindFirstFile on Root directory should Fail"); + if (handle == INVALID_HANDLE_VALUE) + ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number\n"); + handle = FindFirstFileA("C:\\",&search_results); + err = GetLastError(); + ok ( handle == INVALID_HANDLE_VALUE , "FindFirstFile on Root directory should Fail"); + if (handle == INVALID_HANDLE_VALUE) + ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number\n"); + handle = FindFirstFileA("C:\\*",&search_results); + ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed" ); + ok ( FindClose(handle) == TRUE, "Failed to close handle"); +} START_TEST(file) { @@ -763,6 +783,7 @@ START_TEST(file) test_CreateFileW(); test_DeleteFileA(); test_DeleteFileW(); + test_FindFirstFileA(); test_LockFile(); test_offset_in_overlapped_structure(); } diff --git a/files/dos_fs.c b/files/dos_fs.c index 90f77e8619d..6bae3a9ec78 100644 --- a/files/dos_fs.c +++ b/files/dos_fs.c @@ -1937,7 +1937,6 @@ HANDLE WINAPI FindFirstFileExW( UINT codepage; data->dwReserved0 = data->dwReserved1 = 0x0; - if (!lpFileName) return 0; if (lpFileName[0] == '\\' && lpFileName[1] == '\\') { ERR("UNC path name\n"); @@ -1960,6 +1959,16 @@ HANDLE WINAPI FindFirstFileExW( { DOS_FULL_NAME full_name; + if (lpFileName[0] && lpFileName[1] == ':') + { + /* don't allow root directories */ + if (!lpFileName[2] || + ((lpFileName[2] == '/' || lpFileName[2] == '\\') && !lpFileName[3])) + { + SetLastError(ERROR_FILE_NOT_FOUND); + return INVALID_HANDLE_VALUE; + } + } if (!DOSFS_GetFullName( lpFileName, FALSE, &full_name )) break; if (!(handle = GlobalAlloc(GMEM_MOVEABLE, sizeof(FIND_FIRST_INFO)))) break; info = (FIND_FIRST_INFO *)GlobalLock( handle );