From 1408de02ce67d9eb6f11acbde5987de0e9336a02 Mon Sep 17 00:00:00 2001 From: Whindmar Saksit Date: Sat, 23 Mar 2024 22:24:04 +0100 Subject: [PATCH] [SHELL32] SHOpenFolderAndSelectItems should handle children correctly (#6151) - Free pidl from ILCombine. - ILGetNext will never return NULL on valid input, it is not the correct way to check. --- dll/win32/shell32/shlfolder.cpp | 8 ++++++-- sdk/include/reactos/shellutils.h | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dll/win32/shell32/shlfolder.cpp b/dll/win32/shell32/shlfolder.cpp index d4146506038..8f176e8f9e2 100644 --- a/dll/win32/shell32/shlfolder.cpp +++ b/dll/win32/shell32/shlfolder.cpp @@ -372,17 +372,21 @@ SHOpenFolderAndSelectItems(PCIDLIST_ABSOLUTE pidlFolder, DWORD dwFlags) { ERR("SHOpenFolderAndSelectItems() is hackplemented\n"); + CComHeapPtr freeItem; PCIDLIST_ABSOLUTE pidlItem; if (cidl) { /* Firefox sends a full pidl here dispite the fact it is a PCUITEMID_CHILD_ARRAY -_- */ - if (ILGetNext(apidl[0]) != NULL) + if (!ILIsSingle(apidl[0])) { pidlItem = apidl[0]; } else { - pidlItem = ILCombine(pidlFolder, apidl[0]); + HRESULT hr = SHILCombine(pidlFolder, apidl[0], &pidlItem); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + freeItem.Attach(const_cast(pidlItem)); } } else diff --git a/sdk/include/reactos/shellutils.h b/sdk/include/reactos/shellutils.h index 226de2ee325..674221fc106 100644 --- a/sdk/include/reactos/shellutils.h +++ b/sdk/include/reactos/shellutils.h @@ -572,6 +572,10 @@ struct CCoInit #define S_GREATERTHAN S_FALSE #define MAKE_COMPARE_HRESULT(x) ((x)>0 ? S_GREATERTHAN : ((x)<0 ? S_LESSTHAN : S_EQUAL)) +static inline BOOL ILIsSingle(LPCITEMIDLIST pidl) +{ + return pidl == ILFindLastID(pidl); +} static inline PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const* pida) {