From a993c589aebe6a78ccd458f000efc95ff3bde726 Mon Sep 17 00:00:00 2001 From: "Carl J. Bialorucki" Date: Sat, 5 Jul 2025 15:09:23 -0600 Subject: [PATCH] [SHLWAPI_APITEST] Fix heap assertion and test failures (#8217) - Properly initialize a string in SHPropertyBag test. This prevents a heap assertion failure on Vista+ when freed and connected to a debugger. - Adjust a value against Windows 8+ instead of Vista as originally assumed in the IsQSForward test. - Use GetVersion() to check if we are running on NT6+ and test appropriately in the PathIsUNC and PathIsUNCServer tests. --- modules/rostests/apitests/shlwapi/IsQSForward.cpp | 6 ++---- modules/rostests/apitests/shlwapi/PathIsUNC.c | 12 ++++++++---- modules/rostests/apitests/shlwapi/PathIsUNCServer.c | 6 ++++-- modules/rostests/apitests/shlwapi/SHPropertyBag.cpp | 7 +++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/rostests/apitests/shlwapi/IsQSForward.cpp b/modules/rostests/apitests/shlwapi/IsQSForward.cpp index 696c3147c0d..4839380f27c 100644 --- a/modules/rostests/apitests/shlwapi/IsQSForward.cpp +++ b/modules/rostests/apitests/shlwapi/IsQSForward.cpp @@ -13,7 +13,7 @@ #include #include -static BOOL g_bVista = FALSE; +static const BOOL g_bWin8 = IsWindows8OrGreater(); static HRESULT IsQSForwardMockup(_In_opt_ const GUID *pguidCmdGroup, _In_ ULONG cCmds, _In_ OLECMD *prgCmds) @@ -63,7 +63,7 @@ IsQSForwardMockup(_In_opt_ const GUID *pguidCmdGroup, _In_ ULONG cCmds, _In_ OLE { if (!IsEqualGUID(CGID_Explorer, *pguidCmdGroup)) { - if (g_bVista) + if (g_bWin8) return OLECMDERR_E_UNKNOWNGROUP; else return OLECMDERR_E_NOTSUPPORTED; @@ -363,8 +363,6 @@ static VOID TEST_MayExecForwardMockup(VOID) START_TEST(IsQSForward) { - g_bVista = IsWindowsVistaOrGreater(); - TEST_IsQSForward(); TEST_MayQSForwardMockup(); TEST_MayExecForwardMockup(); diff --git a/modules/rostests/apitests/shlwapi/PathIsUNC.c b/modules/rostests/apitests/shlwapi/PathIsUNC.c index d4aef57717c..22c874384d7 100644 --- a/modules/rostests/apitests/shlwapi/PathIsUNC.c +++ b/modules/rostests/apitests/shlwapi/PathIsUNC.c @@ -40,8 +40,10 @@ START_TEST(isuncpath) DO_TEST(FALSE, L"path1"); DO_TEST(FALSE, L"c:\\path1"); - /* MSDN says FALSE but the test shows TRUE on Windows 2003, but returns FALSE on Windows 7 */ - DO_TEST(TRUE, L"\\\\?\\c:\\path1"); + if (GetNTVersion() >= _WIN32_WINNT_VISTA) + DO_TEST(FALSE, L"\\\\?\\c:\\path1"); + else + DO_TEST(TRUE, L"\\\\?\\c:\\path1"); DO_TEST(TRUE, L"\\\\path1\\"); DO_TEST(FALSE, L"//"); @@ -53,6 +55,8 @@ START_TEST(isuncpath) DO_TEST(FALSE, (wchar_t*)NULL); DO_TEST(FALSE, L" "); - /* The test shows TRUE on Windows 2003, but returns FALSE on Windows 7 */ - DO_TEST(TRUE, L"\\\\?\\"); + if (GetNTVersion() >= _WIN32_WINNT_VISTA) + DO_TEST(FALSE, L"\\\\?\\"); + else + DO_TEST(TRUE, L"\\\\?\\"); } diff --git a/modules/rostests/apitests/shlwapi/PathIsUNCServer.c b/modules/rostests/apitests/shlwapi/PathIsUNCServer.c index 140e06a097f..acc2df31992 100644 --- a/modules/rostests/apitests/shlwapi/PathIsUNCServer.c +++ b/modules/rostests/apitests/shlwapi/PathIsUNCServer.c @@ -39,6 +39,8 @@ START_TEST(isuncpathserver) DO_TEST(FALSE, L""); DO_TEST(FALSE, L" "); - /* The test shows TRUE on Windows 2003, but returns FALSE on Windows 7 */ - DO_TEST(TRUE, L"\\\\?"); + if (GetNTVersion() >= _WIN32_WINNT_VISTA) + DO_TEST(FALSE, L"\\\\?"); + else + DO_TEST(TRUE, L"\\\\?"); } diff --git a/modules/rostests/apitests/shlwapi/SHPropertyBag.cpp b/modules/rostests/apitests/shlwapi/SHPropertyBag.cpp index b767d4a4e6d..168e9f82713 100644 --- a/modules/rostests/apitests/shlwapi/SHPropertyBag.cpp +++ b/modules/rostests/apitests/shlwapi/SHPropertyBag.cpp @@ -95,6 +95,13 @@ public: if (lstrcmpiW(pszPropName, L"RECTL2.top") == 0) return E_FAIL; + if (lstrcmpiW(pszPropName, L"Str1") == 0) + { + V_VT(pvari) = VT_BSTR; + V_BSTR(pvari) = SysAllocString(L"TestString"); + return S_OK; + } + if (lstrcmpiW(pszPropName, L"GUID1") == 0) { V_VT(pvari) = (VT_UI1 | VT_ARRAY);