From 961193bc5ddcfe7b6419d32e62f55d9d47f62f2e Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Mon, 10 Jul 2006 20:11:09 -0700 Subject: [PATCH] shell32: Always NULL-terminate path in SHGetPathFromIDList. --- dlls/shell32/pidl.c | 4 ++-- dlls/shell32/tests/shlfolder.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dlls/shell32/pidl.c b/dlls/shell32/pidl.c index e4fe443896b..c849643897b 100644 --- a/dlls/shell32/pidl.c +++ b/dlls/shell32/pidl.c @@ -1240,8 +1240,7 @@ BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath) BOOL bSuccess; bSuccess = SHGetPathFromIDListW(pidl, wszPath); - if (bSuccess) - WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL); return bSuccess; } @@ -1262,6 +1261,7 @@ BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath) TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath); pdump(pidl); + *pszPath = '\0'; if (!pidl) return FALSE; diff --git a/dlls/shell32/tests/shlfolder.c b/dlls/shell32/tests/shlfolder.c index 7a79ab652c1..7751514795d 100644 --- a/dlls/shell32/tests/shlfolder.c +++ b/dlls/shell32/tests/shlfolder.c @@ -771,6 +771,13 @@ static void test_SHGetPathFromIDList(void) if(!pSHGetSpecialFolderPathW) return; + /* Calling SHGetPathFromIDList with no pidl should return the empty string */ + wszPath[0] = 'a'; + wszPath[1] = '\0'; + result = SHGetPathFromIDListW(NULL, wszPath); + ok(!result, "Expected failure\n"); + ok(!wszPath[0], "Expected empty string\n"); + /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */ result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE); ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError()); @@ -794,9 +801,12 @@ static void test_SHGetPathFromIDList(void) } SetLastError(0xdeadbeef); + wszPath[0] = 'a'; + wszPath[1] = '\0'; result = SHGetPathFromIDListW(pidlMyComputer, wszPath); ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n"); ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError()); + ok (!wszPath[0], "Expected empty path\n"); if (result) { IShellFolder_Release(psfDesktop); return;