Commit 5f9f260e authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Avoid truncating the output buffer length in GetCurrentDirectoryA.

parent 76e5c012
......@@ -76,7 +76,7 @@ static DWORD copy_filename_WtoA( LPCWSTR nameW, LPSTR buffer, DWORD len )
ANSI_STRING str;
str.Buffer = buffer;
str.MaximumLength = len;
str.MaximumLength = min( len, UNICODE_STRING_MAX_CHARS );
if (is_ansi)
RtlUnicodeStringToAnsiString( &str, &strW, FALSE );
else
......
......@@ -423,6 +423,7 @@ static void test_InitPathA(CHAR *newdir, CHAR *curDrive, CHAR *otherDrive)
static void test_CurrentDirectoryA(CHAR *origdir, CHAR *newdir)
{
CHAR tmpstr[MAX_PATH],tmpstr1[MAX_PATH];
char *buffer;
DWORD len,len1;
/* Save the original directory, so that we can return to it at the end
of the test
......@@ -437,6 +438,35 @@ static void test_CurrentDirectoryA(CHAR *origdir, CHAR *newdir)
ok(len1==len+1, "GetCurrentDirectoryA returned %d instead of %d\n",len1,len+1);
ok(lstrcmpiA(tmpstr,"aaaaaaa")==0,
"GetCurrentDirectoryA should not have modified the buffer\n");
buffer = HeapAlloc( GetProcessHeap(), 0, 2 * 65536 );
SetLastError( 0xdeadbeef );
strcpy( buffer, "foo" );
len = GetCurrentDirectoryA( 32767, buffer );
ok( len != 0 && len < MAX_PATH, "GetCurrentDirectoryA failed %u err %u\n", len, GetLastError() );
if (len) ok( !strcmp( buffer, origdir ), "wrong result %s\n", buffer );
SetLastError( 0xdeadbeef );
strcpy( buffer, "foo" );
len = GetCurrentDirectoryA( 32768, buffer );
ok( len != 0 && len < MAX_PATH, "GetCurrentDirectoryA failed %u err %u\n", len, GetLastError() );
if (len) ok( !strcmp( buffer, origdir ), "wrong result %s\n", buffer );
SetLastError( 0xdeadbeef );
strcpy( buffer, "foo" );
len = GetCurrentDirectoryA( 65535, buffer );
ok( (len != 0 && len < MAX_PATH) || broken(!len), /* nt4, win2k, xp */ "GetCurrentDirectoryA failed %u err %u\n", len, GetLastError() );
if (len) ok( !strcmp( buffer, origdir ), "wrong result %s\n", buffer );
SetLastError( 0xdeadbeef );
strcpy( buffer, "foo" );
len = GetCurrentDirectoryA( 65536, buffer );
ok( (len != 0 && len < MAX_PATH) || broken(!len), /* nt4 */ "GetCurrentDirectoryA failed %u err %u\n", len, GetLastError() );
if (len) ok( !strcmp( buffer, origdir ), "wrong result %s\n", buffer );
SetLastError( 0xdeadbeef );
strcpy( buffer, "foo" );
len = GetCurrentDirectoryA( 2 * 65536, buffer );
ok( (len != 0 && len < MAX_PATH) || broken(!len), /* nt4 */ "GetCurrentDirectoryA failed %u err %u\n", len, GetLastError() );
if (len) ok( !strcmp( buffer, origdir ), "wrong result %s\n", buffer );
HeapFree( GetProcessHeap(), 0, buffer );
/* SetCurrentDirectoryA shouldn't care whether the string has a
trailing '\\' or not
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment