Michael Stefaniuc : kernel32: Don' t use HIWORD to check for swapped args in GetCurrentDirectoryA.
Alexandre Julliard
julliard at winehq.org
Wed Feb 10 10:44:52 CST 2010
Module: wine
Branch: master
Commit: 0f5d042ff2dd0bdb5abc7249af04fc3e388bae79
URL: http://source.winehq.org/git/wine.git/?a=commit;h=0f5d042ff2dd0bdb5abc7249af04fc3e388bae79
Author: Michael Stefaniuc <mstefani at redhat.de>
Date: Wed Feb 10 12:11:53 2010 +0100
kernel32: Don't use HIWORD to check for swapped args in GetCurrentDirectoryA.
---
dlls/kernel32/path.c | 4 ++--
dlls/kernel32/tests/path.c | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index 0a02681..d77ecc1 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -1400,13 +1400,13 @@ UINT WINAPI GetCurrentDirectoryA( UINT buflen, LPSTR buf )
WCHAR bufferW[MAX_PATH];
DWORD ret;
- if (buflen && buf && !HIWORD(buf))
+ if (buflen && buf && ((ULONG_PTR)buf >> 16) == 0)
{
/* Win9x catches access violations here, returning zero.
* This behaviour resulted in some people not noticing
* that they got the argument order wrong. So let's be
* nice and fail gracefully if buf is invalid and looks
- * more like a buflen (which is probably MAX_PATH). */
+ * more like a buflen. */
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c
index e533bd0..be01948 100644
--- a/dlls/kernel32/tests/path.c
+++ b/dlls/kernel32/tests/path.c
@@ -467,6 +467,16 @@ static void test_CurrentDirectoryA(CHAR *origdir, CHAR *newdir)
if (len) ok( !strcmp( buffer, origdir ), "wrong result %s\n", buffer );
HeapFree( GetProcessHeap(), 0, buffer );
+/* Check for crash prevention on swapped args. Crashes all but Win9x.
+*/
+ if (0)
+ {
+ SetLastError( 0xdeadbeef );
+ len = GetCurrentDirectoryA( 42, (LPSTR)(MAX_PATH + 42) );
+ ok( len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
+ "GetCurrentDirectoryA failed to fail %u err %u\n", len, GetLastError() );
+ }
+
/* SetCurrentDirectoryA shouldn't care whether the string has a
trailing '\\' or not
*/
More information about the wine-cvs
mailing list