This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit fe09cdbe8a936f064d5fb852216373e51e44e216
Author: Arrigo Marchiori <[email protected]>
AuthorDate: Fri Jun 3 10:55:18 2022 +0200

    Copy data because iterators could be invalidated
    
    (cherry picked from commit a1a746b3aa762f45e2be14f8d65d0b384c6c516f)
---
 main/svl/source/inc/passwordcontainer.hxx             |  2 +-
 .../source/passwordcontainer/passwordcontainer.cxx    | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/main/svl/source/inc/passwordcontainer.hxx 
b/main/svl/source/inc/passwordcontainer.hxx
index 3547f65d0e..871cad23ce 100644
--- a/main/svl/source/inc/passwordcontainer.hxx
+++ b/main/svl/source/inc/passwordcontainer.hxx
@@ -270,7 +270,7 @@ private:
                                         const 
::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler 
>& Handler )
                                                         
throw(::com::sun::star::uno::RuntimeException);
 bool createUrlRecord( 
-    const PassMap::iterator & rIter, 
+    const PairUrlRecord & rPair,
     bool bName,
     const ::rtl::OUString & aName,
     const ::com::sun::star::uno::Reference< 
::com::sun::star::task::XInteractionHandler >& aHandler,
diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx 
b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index c9b91fec5f..5c581d46df 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -857,7 +857,7 @@ Sequence< UserRecord > PasswordContainer::FindUsr( const 
list< NamePassRecord >&
 //-------------------------------------------------------------------------
 
 bool PasswordContainer::createUrlRecord(
-    const PassMap::iterator & rIter,
+    const PairUrlRecord & rPair,
     bool bName,
     const ::rtl::OUString & aName,
     const Reference< XInteractionHandler >& aHandler,
@@ -867,18 +867,18 @@ bool PasswordContainer::createUrlRecord(
     if ( bName )
     {
         Sequence< UserRecord > aUsrRec
-            = FindUsr( rIter->second, aName, aHandler );
+            = FindUsr( rPair.second, aName, aHandler );
         if( aUsrRec.getLength() )
         {
-            rRec = UrlRecord( rIter->first, aUsrRec );
+            rRec = UrlRecord( rPair.first, aUsrRec );
             return true;
         }
     }
     else
     {
         rRec = UrlRecord(
-            rIter->first,
-            CopyToUserRecordSequence( rIter->second, aHandler ) );
+            rPair.first,
+            CopyToUserRecordSequence( rPair.second, aHandler ) );
         return true;
     }
     return false;
@@ -904,10 +904,14 @@ UrlRecord PasswordContainer::find(
         {
             // first look for <url>/somename and then look for 
<url>/somename/...
             PassMap::iterator aIter = m_aContainer.find( aUrl );
+            // Note that this iterator may be invalidated by the
+            // side-effects of createUrlRecord(), so we have to work with a
+            // copy of the pointed elements
             if( aIter != m_aContainer.end() )
             {
+                const PairUrlRecord rPairUrlRecord = *aIter;
                 UrlRecord aRec;
-                if ( createUrlRecord( aIter, bName, aName, aHandler, aRec ) )
+                if ( createUrlRecord( rPairUrlRecord, bName, aName, aHandler, 
aRec ) )
                   return aRec;
             }
             else
@@ -919,8 +923,9 @@ UrlRecord PasswordContainer::find(
                 aIter = m_aContainer.lower_bound( tmpUrl );
                 if( aIter != m_aContainer.end() && aIter->first.match( tmpUrl 
) )
                 {
+                    const PairUrlRecord rPairUrlRecord = *aIter;
                     UrlRecord aRec;
-                    if ( createUrlRecord( aIter, bName, aName, aHandler, aRec 
) )
+                    if ( createUrlRecord( rPairUrlRecord, bName, aName, 
aHandler, aRec ) )
                       return aRec;
                 }
             }

Reply via email to