[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.
This commit is contained in:
Whindmar Saksit 2024-03-23 22:24:04 +01:00 committed by GitHub
parent f9c93888b7
commit 1408de02ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -372,17 +372,21 @@ SHOpenFolderAndSelectItems(PCIDLIST_ABSOLUTE pidlFolder,
DWORD dwFlags) DWORD dwFlags)
{ {
ERR("SHOpenFolderAndSelectItems() is hackplemented\n"); ERR("SHOpenFolderAndSelectItems() is hackplemented\n");
CComHeapPtr<ITEMIDLIST> freeItem;
PCIDLIST_ABSOLUTE pidlItem; PCIDLIST_ABSOLUTE pidlItem;
if (cidl) if (cidl)
{ {
/* Firefox sends a full pidl here dispite the fact it is a PCUITEMID_CHILD_ARRAY -_- */ /* 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]; pidlItem = apidl[0];
} }
else else
{ {
pidlItem = ILCombine(pidlFolder, apidl[0]); HRESULT hr = SHILCombine(pidlFolder, apidl[0], &pidlItem);
if (FAILED_UNEXPECTEDLY(hr))
return hr;
freeItem.Attach(const_cast<PIDLIST_ABSOLUTE>(pidlItem));
} }
} }
else else

View file

@ -572,6 +572,10 @@ struct CCoInit
#define S_GREATERTHAN S_FALSE #define S_GREATERTHAN S_FALSE
#define MAKE_COMPARE_HRESULT(x) ((x)>0 ? S_GREATERTHAN : ((x)<0 ? S_LESSTHAN : S_EQUAL)) #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) static inline PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const* pida)
{ {