FindFirstFile on root directory should fail.

This commit is contained in:
Uwe Bonnes 2003-04-17 02:10:04 +00:00 committed by Alexandre Julliard
parent 3dddc114cf
commit 0de21b651e
2 changed files with 31 additions and 1 deletions

View File

@ -746,6 +746,26 @@ static void test_LockFile(void)
DeleteFileA( filename ); 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) START_TEST(file)
{ {
@ -763,6 +783,7 @@ START_TEST(file)
test_CreateFileW(); test_CreateFileW();
test_DeleteFileA(); test_DeleteFileA();
test_DeleteFileW(); test_DeleteFileW();
test_FindFirstFileA();
test_LockFile(); test_LockFile();
test_offset_in_overlapped_structure(); test_offset_in_overlapped_structure();
} }

View File

@ -1937,7 +1937,6 @@ HANDLE WINAPI FindFirstFileExW(
UINT codepage; UINT codepage;
data->dwReserved0 = data->dwReserved1 = 0x0; data->dwReserved0 = data->dwReserved1 = 0x0;
if (!lpFileName) return 0;
if (lpFileName[0] == '\\' && lpFileName[1] == '\\') if (lpFileName[0] == '\\' && lpFileName[1] == '\\')
{ {
ERR("UNC path name\n"); ERR("UNC path name\n");
@ -1960,6 +1959,16 @@ HANDLE WINAPI FindFirstFileExW(
{ {
DOS_FULL_NAME full_name; 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 (!DOSFS_GetFullName( lpFileName, FALSE, &full_name )) break;
if (!(handle = GlobalAlloc(GMEM_MOVEABLE, sizeof(FIND_FIRST_INFO)))) break; if (!(handle = GlobalAlloc(GMEM_MOVEABLE, sizeof(FIND_FIRST_INFO)))) break;
info = (FIND_FIRST_INFO *)GlobalLock( handle ); info = (FIND_FIRST_INFO *)GlobalLock( handle );