kernel32: Fix GetTempFileName with invalid path.

Found by Oskar Eisemuth.
This commit is contained in:
Louis Lenders 2010-10-20 20:27:38 +02:00 committed by Alexandre Julliard
parent 105793bff7
commit 8819ae1e66
2 changed files with 10 additions and 2 deletions

View File

@ -660,6 +660,7 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR
int i;
LPWSTR p;
DWORD attr;
if ( !path || !buffer )
{
@ -667,6 +668,15 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR
return 0;
}
/* ensure that the provided directory exists */
attr = GetFileAttributesW(path);
if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
{
TRACE("path not found %s\n", debugstr_w(path));
SetLastError( ERROR_DIRECTORY );
return 0;
}
strcpyW( buffer, path );
p = buffer + strlenW(buffer);

View File

@ -364,9 +364,7 @@ static void test_InitPathA(CHAR *newdir, CHAR *curDrive, CHAR *otherDrive)
/* Non-existent path */
sprintf(invalid_dir, "%s\%s",tmppath,"non_existent_dir_1jwj3y32nb3");
SetLastError(0xdeadbeef);
todo_wine
ok(!GetTempFileNameA(invalid_dir,"tfn",unique,newdir),"GetTempFileNameA should have failed\n");
todo_wine
ok(GetLastError()==ERROR_DIRECTORY || broken(GetLastError()==ERROR_PATH_NOT_FOUND)/*win98*/,
"got %d, expected ERROR_DIRECTORY\n", GetLastError());