tdf#100783 Avoid infinite recursion in Content::getObject()

With certain CMIS host URLs, it is possible that exception handler
in Content::getObject() will recursively call itself with the same
data (xParent from the same URL).

This patch checks if the new URL is not the same as own, to avoid
this.

Change-Id: Ifaeb4ff27a9c809c5c96fa35ec190c3263a8fe62
Reviewed-on: https://gerrit.libreoffice.org/26977
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
This commit is contained in:
Mike Kaganski
2016-07-06 19:45:41 +10:00
committed by Andras Timar
parent a389012950
commit d1a32a01be

View File

@@ -538,17 +538,20 @@ namespace cmis
string sName = OUSTR_TO_STDSTR( aParentUrl.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ) );
aParentUrl.removeSegment( );
OUString sParentUrl = aParentUrl.GetMainURL( INetURLObject::NO_DECODE );
rtl::Reference<Content> xParent( new Content(m_xContext, m_pProvider, new ucbhelper::ContentIdentifier( sParentUrl )) );
libcmis::FolderPtr pParentFolder = boost::dynamic_pointer_cast< libcmis::Folder >( xParent->getObject( xEnv ) );
if ( pParentFolder )
// Avoid infinite recursion if sParentUrl == m_sURL
if (sParentUrl != m_sURL)
{
vector< libcmis::ObjectPtr > children = pParentFolder->getChildren( );
for ( vector< libcmis::ObjectPtr >::iterator it = children.begin( );
it != children.end() && !m_pObject; ++it )
rtl::Reference<Content> xParent(new Content(m_xContext, m_pProvider, new ucbhelper::ContentIdentifier(sParentUrl)));
libcmis::FolderPtr pParentFolder = boost::dynamic_pointer_cast< libcmis::Folder >(xParent->getObject(xEnv));
if (pParentFolder)
{
if ( ( *it )->getName( ) == sName )
m_pObject = *it;
vector< libcmis::ObjectPtr > children = pParentFolder->getChildren();
for (vector< libcmis::ObjectPtr >::iterator it = children.begin();
it != children.end() && !m_pObject; ++it)
{
if ((*it)->getName() == sName)
m_pObject = *it;
}
}
}