Simplify Sequence iterations in svl [only passwordcontainer.cxx]
authorArkadiy Illarionov <qarkai@gmail.com>
Sat, 13 Jul 2019 18:29:10 +0000 (21:29 +0300)
committerBastien Roucariès <rouca@debian.org>
Sat, 12 Aug 2023 19:58:29 +0000 (20:58 +0100)
Needed for fixing CVE-2022-26307

Use range-based loops, STL and comphelper functions

Reviewed-on: https://gerrit.libreoffice.org/75563
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
(cherry picked from commit c9cce0d931b41ede0eca14b2ed2b84453f048362)

Change-Id: I1c3dbf194600bec60c0881d2d19ff07b89d8333b
origin: https://github.com/LibreOffice/core/commit/bfec3cf63ef43cc86e9a2fd90600d91b5fefe0c3.patch

Gbp-Pq: Name 0069-Simplify-Sequence-iterations-in-svl-only-passwordcon.patch

svl/source/passwordcontainer/passwordcontainer.cxx

index cc45406175377c3d4aaa51924f32d2daeb00e700..c21f748a0c294a35851c6a6ca6b4bec276d299ff 100644 (file)
@@ -186,22 +186,20 @@ PassMap StorageItem::getInfo()
     Sequence< OUString > aNodeNames     = ConfigItem::GetNodeNames( "Store" );
     sal_Int32 aNodeCount = aNodeNames.getLength();
     Sequence< OUString > aPropNames( aNodeCount );
-    sal_Int32 aNodeInd;
 
-    for( aNodeInd = 0; aNodeInd < aNodeCount; ++aNodeInd )
-    {
-        aPropNames[aNodeInd]  = "Store/Passwordstorage['" + aNodeNames[aNodeInd] + "']/Password";
-    }
+    std::transform(aNodeNames.begin(), aNodeNames.end(), aPropNames.begin(),
+        [](const OUString& rName) -> OUString {
+            return "Store/Passwordstorage['" + rName + "']/Password"; });
 
     Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aPropNames );
 
-    if( aPropertyValues.getLength() != aNodeNames.getLength() )
+    if( aPropertyValues.getLength() != aNodeCount )
     {
-        OSL_ENSURE( aPropertyValues.getLength() == aNodeNames.getLength(), "Problems during reading" );
+        OSL_FAIL( "Problems during reading" );
         return aResult;
     }
 
-    for( aNodeInd = 0; aNodeInd < aNodeCount; ++aNodeInd )
+    for( sal_Int32 aNodeInd = 0; aNodeInd < aNodeCount; ++aNodeInd )
     {
         std::vector< OUString > aUrlUsr = getInfoFromInd( aNodeNames[aNodeInd] );
 
@@ -254,7 +252,7 @@ bool StorageItem::useStorage()
 
     if( aPropertyValues.getLength() != aNodeNames.getLength() )
     {
-        OSL_ENSURE( aPropertyValues.getLength() == aNodeNames.getLength(), "Problems during reading" );
+        OSL_FAIL( "Problems during reading" );
         return false;
     }
 
@@ -298,7 +296,7 @@ bool StorageItem::getEncodedMP( OUString& aResult )
 
     if( aPropertyValues.getLength() != aNodeNames.getLength() )
     {
-        OSL_ENSURE( aPropertyValues.getLength() == aNodeNames.getLength(), "Problems during reading" );
+        OSL_FAIL( "Problems during reading" );
         return false;
     }
 
@@ -1149,11 +1147,9 @@ sal_Bool SAL_CALL PasswordContainer::changeMasterPassword( const uno::Reference<
                 m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
 
                 // store all the entries with the new password
-                for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ )
-                    for ( int nNameInd = 0; nNameInd< aPersistent[nURLInd].UserList.getLength(); nNameInd++ )
-                        addPersistent( aPersistent[nURLInd].Url,
-                                       aPersistent[nURLInd].UserList[nNameInd].UserName,
-                                       aPersistent[nURLInd].UserList[nNameInd].Passwords,
+                for ( const auto& rURL : aPersistent )
+                    for ( const auto& rUser : rURL.UserList )
+                        addPersistent( rURL.Url, rUser.UserName, rUser.Passwords,
                                        uno::Reference< task::XInteractionHandler >() );
 
                 bResult = true;
@@ -1253,11 +1249,9 @@ sal_Bool SAL_CALL PasswordContainer::useDefaultMasterPassword( const uno::Refere
                 m_pStorageFile->setEncodedMP( OUString(), true );
 
                 // store all the entries with the new password
-                for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ )
-                    for ( int nNameInd = 0; nNameInd< aPersistent[nURLInd].UserList.getLength(); nNameInd++ )
-                        addPersistent( aPersistent[nURLInd].Url,
-                                       aPersistent[nURLInd].UserList[nNameInd].UserName,
-                                       aPersistent[nURLInd].UserList[nNameInd].Passwords,
+                for ( const auto& rURL : aPersistent )
+                    for ( const auto& rUser : rURL.UserList )
+                        addPersistent( rURL.Url, rUser.UserName, rUser.Passwords,
                                        uno::Reference< task::XInteractionHandler >() );
 
                 bResult = true;