From 0e0c90edbb324e35d1656c610866e70cc8a43d5d Mon Sep 17 00:00:00 2001 From: David Quintana Date: Sun, 12 Apr 2015 01:34:53 +0000 Subject: [PATCH] [NTOBJSHEX] * Make the info struct pointers const, to ensure we are not modifying the contents from the const idlists. * Disable checking that the provided PIDL is part of the folder. Fixes enumeration in ros, but feels a lot like hiding a bug. CORE-9432 #resolve svn path=/trunk/; revision=67166 --- reactos/dll/shellext/ntobjshex/ntobjns.cpp | 55 ++++++++++++++------ reactos/dll/shellext/ntobjshex/precomp.h | 3 ++ reactos/dll/shellext/ntobjshex/regfolder.cpp | 51 +++++++++++++----- 3 files changed, 78 insertions(+), 31 deletions(-) diff --git a/reactos/dll/shellext/ntobjshex/ntobjns.cpp b/reactos/dll/shellext/ntobjshex/ntobjns.cpp index 10f491cc7f7..86fb289306b 100644 --- a/reactos/dll/shellext/ntobjshex/ntobjns.cpp +++ b/reactos/dll/shellext/ntobjshex/ntobjns.cpp @@ -199,7 +199,7 @@ public: return S_OK; } - HRESULT FindPidlInList(PCUITEMID_CHILD pcidl, NtPidlEntry ** pinfo) + HRESULT FindPidlInList(PCUITEMID_CHILD pcidl, const NtPidlEntry ** pinfo) { HRESULT hr; @@ -326,7 +326,7 @@ public: return S_OK; } - static LPITEMIDLIST CreatePidlFromItem(NtPidlEntry * entry) + static LPITEMIDLIST CreatePidlFromItem(const NtPidlEntry * entry) { LPITEMIDLIST idl = (LPITEMIDLIST) CoTaskMemAlloc(entry->cb + 2); if (!idl) @@ -336,7 +336,7 @@ public: return idl; } - static HRESULT CompareIDs(LPARAM lParam, NtPidlEntry * first, NtPidlEntry * second) + static HRESULT CompareIDs(LPARAM lParam, const NtPidlEntry * first, const NtPidlEntry * second) { if ((lParam & 0xFFFF0000) == SHCIDS_ALLFIELDS) { @@ -431,7 +431,7 @@ public: return E_INVALIDARG; } - static HRESULT CompareIDs(LPARAM lParam, NtPidlEntry * first, LPCITEMIDLIST pcidl) + static HRESULT CompareIDs(LPARAM lParam, const NtPidlEntry * first, LPCITEMIDLIST pcidl) { LPCITEMIDLIST p = pcidl; NtPidlEntry * second = (NtPidlEntry*) &(p->mkid); @@ -451,7 +451,7 @@ public: return CompareIDs(lParam, first, pcidl2); } - static ULONG ConvertAttributes(NtPidlEntry * entry, PULONG inMask) + static ULONG ConvertAttributes(const NtPidlEntry * entry, PULONG inMask) { ULONG mask = inMask ? *inMask : 0xFFFFFFFF; ULONG flags = SFGAO_HASPROPSHEET | SFGAO_CANLINK; @@ -470,7 +470,7 @@ public: BOOL IsFolder(LPCITEMIDLIST pcidl) { - NtPidlEntry * entry; + const NtPidlEntry * entry; HRESULT hr = FindPidlInList(pcidl, &entry); if (FAILED_UNEXPECTEDLY(hr)) return FALSE; @@ -668,7 +668,7 @@ HRESULT STDMETHODCALLTYPE CNtObjectFolder::BindToObject( REFIID riid, void **ppvOut) { - NtPidlEntry * info; + const NtPidlEntry * info; HRESULT hr; if (IsEqualIID(riid, IID_IShellFolder)) @@ -816,8 +816,7 @@ HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetAttributesOf( PCUITEMID_CHILD_ARRAY apidl, SFGAOF *rgfInOut) { - NtPidlEntry * info; - HRESULT hr; + const NtPidlEntry * info; TRACE("GetAttributesOf\n"); @@ -831,9 +830,15 @@ HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetAttributesOf( { PCUITEMID_CHILD pidl = apidl[i]; - hr = m_PidlManager->FindPidlInList(pidl, &info); +#ifndef DISABLE_STRICT_PIDL_CHECK + HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const NtPidlEntry *) pidl; + if (info->magic != NT_OBJECT_PIDL_MAGIC) + return E_INVALIDARG; +#endif // Update attributes. *rgfInOut = m_PidlManager->ConvertAttributes(info, rgfInOut); @@ -912,14 +917,20 @@ HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDisplayNameOf( SHGDNF uFlags, STRRET *lpName) { - NtPidlEntry * info; + const NtPidlEntry * info; HRESULT hr; TRACE("GetDisplayNameOf %p\n", pidl); +#ifndef DISABLE_STRICT_PIDL_CHECK hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const NtPidlEntry *) pidl; + if (info->magic != NT_OBJECT_PIDL_MAGIC) + return E_INVALIDARG; +#endif if ((GET_SHGDN_RELATION(uFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING)) @@ -1085,16 +1096,21 @@ HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDetailsEx( const SHCOLUMNID *pscid, VARIANT *pv) { - NtPidlEntry * info; - HRESULT hr; + const NtPidlEntry * info; TRACE("GetDetailsEx\n"); if (pidl) { - hr = m_PidlManager->FindPidlInList(pidl, &info); +#ifndef DISABLE_STRICT_PIDL_CHECK + HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const NtPidlEntry *) pidl; + if (info->magic != NT_OBJECT_PIDL_MAGIC) + return E_INVALIDARG; +#endif static const GUID storage = PSGUID_STORAGE; if (IsEqualGUID(pscid->fmtid, storage)) @@ -1163,16 +1179,21 @@ HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDetailsOf( UINT iColumn, SHELLDETAILS *psd) { - NtPidlEntry * info; - HRESULT hr; + const NtPidlEntry * info; TRACE("GetDetailsOf\n"); if (pidl) { - hr = m_PidlManager->FindPidlInList(pidl, &info); +#ifndef DISABLE_STRICT_PIDL_CHECK + HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const NtPidlEntry *) pidl; + if (info->magic != NT_OBJECT_PIDL_MAGIC) + return E_INVALIDARG; +#endif switch (iColumn) { diff --git a/reactos/dll/shellext/ntobjshex/precomp.h b/reactos/dll/shellext/ntobjshex/precomp.h index c1c55412f0e..b3a6a259c7b 100644 --- a/reactos/dll/shellext/ntobjshex/precomp.h +++ b/reactos/dll/shellext/ntobjshex/precomp.h @@ -48,3 +48,6 @@ DEFINE_GUID(CLSID_NtObjectFolder, #include "ntobjns.h" #include "regfolder.h" + +// Workaround for missing entries +#define DISABLE_STRICT_PIDL_CHECKS \ No newline at end of file diff --git a/reactos/dll/shellext/ntobjshex/regfolder.cpp b/reactos/dll/shellext/ntobjshex/regfolder.cpp index f96ecfa75ca..ff78c4d62ba 100644 --- a/reactos/dll/shellext/ntobjshex/regfolder.cpp +++ b/reactos/dll/shellext/ntobjshex/regfolder.cpp @@ -194,7 +194,7 @@ public: return S_OK; } - HRESULT FindPidlInList(PCUITEMID_CHILD pcidl, RegPidlEntry ** pinfo) + HRESULT FindPidlInList(PCUITEMID_CHILD pcidl, const RegPidlEntry ** pinfo) { HRESULT hr; @@ -323,7 +323,7 @@ public: } - static LPITEMIDLIST CreatePidlFromItem(RegPidlEntry * entry) + static LPITEMIDLIST CreatePidlFromItem(const RegPidlEntry * entry) { LPITEMIDLIST idl = (LPITEMIDLIST) CoTaskMemAlloc(entry->cb + 2); if (!idl) @@ -333,7 +333,7 @@ public: return idl; } - static HRESULT CompareIDs(LPARAM lParam, RegPidlEntry * first, RegPidlEntry * second) + static HRESULT CompareIDs(LPARAM lParam, const RegPidlEntry * first, const RegPidlEntry * second) { if ((lParam & 0xFFFF0000) == SHCIDS_ALLFIELDS) { @@ -418,7 +418,7 @@ public: return E_INVALIDARG; } - static HRESULT CompareIDs(LPARAM lParam, RegPidlEntry * first, LPCITEMIDLIST pcidl) + static HRESULT CompareIDs(LPARAM lParam, const RegPidlEntry * first, LPCITEMIDLIST pcidl) { LPCITEMIDLIST p = pcidl; RegPidlEntry * second = (RegPidlEntry*) &(p->mkid); @@ -438,7 +438,7 @@ public: return CompareIDs(lParam, first, pcidl2); } - static ULONG ConvertAttributes(RegPidlEntry * entry, PULONG inMask) + static ULONG ConvertAttributes(const RegPidlEntry * entry, PULONG inMask) { ULONG mask = inMask ? *inMask : 0xFFFFFFFF; ULONG flags = 0; @@ -452,7 +452,7 @@ public: BOOL IsFolder(LPCITEMIDLIST pcidl) { - RegPidlEntry * entry; + const RegPidlEntry * entry; HRESULT hr = FindPidlInList(pcidl, &entry); if (FAILED_UNEXPECTEDLY(hr)) return FALSE; @@ -512,7 +512,7 @@ public: } } - HRESULT FormatContentsForDisplay(RegPidlEntry * info, PCWSTR * strContents) + HRESULT FormatContentsForDisplay(const RegPidlEntry * info, PCWSTR * strContents) { PVOID td = (((PBYTE) info) + FIELD_OFFSET(RegPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); @@ -752,7 +752,7 @@ HRESULT STDMETHODCALLTYPE CRegistryFolder::BindToObject( REFIID riid, void **ppvOut) { - RegPidlEntry * info; + const RegPidlEntry * info; HRESULT hr; if (IsEqualIID(riid, IID_IShellFolder)) @@ -866,8 +866,7 @@ HRESULT STDMETHODCALLTYPE CRegistryFolder::GetAttributesOf( PCUITEMID_CHILD_ARRAY apidl, SFGAOF *rgfInOut) { - RegPidlEntry * info; - HRESULT hr; + const RegPidlEntry * info; TRACE("GetAttributesOf\n"); @@ -881,9 +880,15 @@ HRESULT STDMETHODCALLTYPE CRegistryFolder::GetAttributesOf( { PCUITEMID_CHILD pidl = apidl[i]; - hr = m_PidlManager->FindPidlInList(pidl, &info); +#ifndef DISABLE_STRICT_PIDL_CHECK + HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const RegPidlEntry *) pidl; + if (info->magic != REGISTRY_PIDL_MAGIC) + return E_INVALIDARG; +#endif // Update attributes. *rgfInOut = m_PidlManager->ConvertAttributes(info, rgfInOut); @@ -962,14 +967,20 @@ HRESULT STDMETHODCALLTYPE CRegistryFolder::GetDisplayNameOf( SHGDNF uFlags, STRRET *lpName) { - RegPidlEntry * info; + const RegPidlEntry * info; HRESULT hr; TRACE("GetDisplayNameOf %p\n", pidl); +#ifndef DISABLE_STRICT_PIDL_CHECK hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const RegPidlEntry *) pidl; + if (info->magic != REGISTRY_PIDL_MAGIC) + return E_INVALIDARG; +#endif if ((GET_SHGDN_RELATION(uFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING)) @@ -1134,16 +1145,22 @@ HRESULT STDMETHODCALLTYPE CRegistryFolder::GetDetailsEx( const SHCOLUMNID *pscid, VARIANT *pv) { - RegPidlEntry * info; + const RegPidlEntry * info; HRESULT hr; TRACE("GetDetailsEx\n"); if (pidl) { +#ifndef DISABLE_STRICT_PIDL_CHECK hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const RegPidlEntry *) pidl; + if (info->magic != REGISTRY_PIDL_MAGIC) + return E_INVALIDARG; +#endif static const GUID storage = PSGUID_STORAGE; if (IsEqualGUID(pscid->fmtid, storage)) @@ -1208,16 +1225,22 @@ HRESULT STDMETHODCALLTYPE CRegistryFolder::GetDetailsOf( UINT iColumn, SHELLDETAILS *psd) { - RegPidlEntry * info; + const RegPidlEntry * info; HRESULT hr; TRACE("GetDetailsOf\n"); if (pidl) { +#ifndef DISABLE_STRICT_PIDL_CHECK hr = m_PidlManager->FindPidlInList(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; +#else + info = (const RegPidlEntry *) pidl; + if (info->magic != REGISTRY_PIDL_MAGIC) + return E_INVALIDARG; +#endif switch (iColumn) {