From 3a78ec672a4c1635d848e0253f45127cb8690f26 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Sat, 20 Oct 2018 23:46:38 +0300 Subject: [PATCH] kernel32: GetShortPathName should fail when called with a wildcard. Signed-off-by: Dmitry Timoshkov Signed-off-by: Alexandre Julliard --- dlls/kernel32/path.c | 11 ++++++++++- dlls/kernel32/tests/path.c | 2 -- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c index 7dcb9374307..a9db7e8cdf5 100644 --- a/dlls/kernel32/path.c +++ b/dlls/kernel32/path.c @@ -45,6 +45,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(file); static int path_safe_mode = -1; /* path mode set by SetSearchPathMode */ +static const WCHAR wildcardsW[] = {'*','?',0}; + /* check if a file name is for an executable file (.exe or .com) */ static inline BOOL is_executable( const WCHAR *name ) { @@ -445,7 +447,7 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl WIN32_FIND_DATAW wfd; HANDLE goit; - TRACE("%s\n", debugstr_w(longpath)); + TRACE("%s,%p,%u\n", debugstr_w(longpath), shortpath, shortlen); if (!longpath) { @@ -474,6 +476,13 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl sp = lp = 4; } + if (strpbrkW(longpath + lp, wildcardsW)) + { + HeapFree(GetProcessHeap(), 0, tmpshortpath); + SetLastError(ERROR_INVALID_NAME); + return 0; + } + /* check for drive letter */ if (longpath[lp] != '/' && longpath[lp + 1] == ':' ) { diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c index 5ca69d3b3c9..f0cfb4d43c2 100644 --- a/dlls/kernel32/tests/path.c +++ b/dlls/kernel32/tests/path.c @@ -1477,9 +1477,7 @@ static void test_GetShortPathNameW(void) lstrcpyW(ptr, wildW); SetLastError(0xdeadbeef); length = GetShortPathNameW( path, short_path, ARRAY_SIZE( short_path ) ); -todo_wine ok(!length, "GetShortPathNameW should fail\n"); -todo_wine ok(GetLastError() == ERROR_INVALID_NAME, "wrong error %d\n", GetLastError()); lstrcpyW(ptr, a_bcdeW);