Alexandre Julliard : kernel32: Avoid truncating the output buffer length in GetCurrentDirectoryA.
Alexandre Julliard
julliard at winehq.org
Mon Feb 1 08:56:03 CST 2010
Module: wine
Branch: master
Commit: 5f9f260e426cc7de9a7548b38c9a006e1338e6fc
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5f9f260e426cc7de9a7548b38c9a006e1338e6fc
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Feb 1 13:22:41 2010 +0100
kernel32: Avoid truncating the output buffer length in GetCurrentDirectoryA.
---
dlls/kernel32/path.c | 2 +-
dlls/kernel32/tests/path.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index a304cb2..0a02681 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -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
diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c
index 4c0aac5..e533bd0 100644
--- a/dlls/kernel32/tests/path.c
+++ b/dlls/kernel32/tests/path.c
@@ -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
*/
More information about the wine-cvs
mailing list