From 1922f3beb55fee7569228a70b591ee44c9c3623e Mon Sep 17 00:00:00 2001 From: Louis Lenders Date: Wed, 20 Oct 2010 20:27:38 +0200 Subject: kernel32: Fix GetTempFileName with invalid path. Found by Oskar Eisemuth --- dlls/kernel32/path.c | 10 ++++++++++ dlls/kernel32/tests/path.c | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c index 294ea1c..2f400d4 100644 --- a/dlls/kernel32/path.c +++ b/dlls/kernel32/path.c @@ -660,6 +660,7 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR int i; LPWSTR p; + DWORD dwAttr; 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 */ + dwAttr = GetFileAttributesW(path); + if (dwAttr == INVALID_FILE_ATTRIBUTES || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) + { + TRACE("path not found %s\n", debugstr_w(path)); + SetLastError( ERROR_DIRECTORY ); + return 0; + } + strcpyW( buffer, path ); p = buffer + strlenW(buffer); diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c index 0200fc4..0065ebf 100644 --- a/dlls/kernel32/tests/path.c +++ b/dlls/kernel32/tests/path.c @@ -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()); -- 1.7.1