diff -r b75757c81051 -r 318c4eab2439 boottimeintegritycheck/src/IntegrityCheck.cpp --- a/boottimeintegritycheck/src/IntegrityCheck.cpp Fri Mar 19 09:41:08 2010 +0200 +++ b/boottimeintegritycheck/src/IntegrityCheck.cpp Fri Apr 16 15:53:24 2010 +0300 @@ -78,6 +78,37 @@ // FUNCTION PROTOTYPES +template +class CleanupResetAndDestroy + { +public: + inline static void PushL(T& aRef); +private: + static void ResetAndDestroy(TAny *aPtr); + }; + +template +inline void CleanupResetAndDestroyPushL(T& aRef); + +template +inline void CleanupResetAndDestroy::PushL(T& aRef) + { + CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef)); + } + +template +void CleanupResetAndDestroy::ResetAndDestroy(TAny *aPtr) + { + static_cast(aPtr)->ResetAndDestroy(); + } + +template +inline void CleanupResetAndDestroyPushL(T& aRef) + { + CleanupResetAndDestroy::PushL(aRef); + } + + LOCAL_C TInt ThreadStartL(); LOCAL_C TInt ReadCertificatesL( @@ -390,10 +421,14 @@ BTIC_TRACE_PRINT_NUM("Updated store read enabled(1) = %d",certFileFound); BTIC_TRACE_PRINT_NUM("Binaries check enabled(0) = %d",binariesCheckEnbled); - +//FIX // Create pointer array for root certificates. - RPointerArray x509CertArray; + RPointerArray x509CertArray; + CleanupResetAndDestroyPushL( x509CertArray ); + pushToStack++; RPointerArray certCapaArray; + CleanupResetAndDestroyPushL( certCapaArray ); + pushToStack++; TInt fileError = 0; // Read root certificates if needed. @@ -413,16 +448,19 @@ { BTIC_TRACE_PRINT("ERROR Can't read root certificates ! ! !"); CleanupStack::PopAndDestroy( pushToStack ); - x509CertArray.ResetAndDestroy(); - certCapaArray.ResetAndDestroy(); + User::Leave( fileError ); } } - + // Create temporary pointer array for C-drive updated certificates. - RPointerArray tempCertArray; - RPointerArray tempCapaArray; - + RPointerArray tempCertArray; + CleanupResetAndDestroyPushL( tempCertArray ); + pushToStack++; + RPointerArray tempCapaArray; + CleanupResetAndDestroyPushL( tempCapaArray ); + pushToStack++; + // If candidate for certstore file is found read it and validate file. if ( certFileFound ) { @@ -512,13 +550,9 @@ */ BTIC_TRACE_PRINT("\nProgram complete\n"); - // DELETE ALL ARRAYS AND ARRAY CONTENT - x509CertArray.ResetAndDestroy(); - tempCertArray.ResetAndDestroy(); - certCapaArray.ResetAndDestroy(); - tempCapaArray.ResetAndDestroy(); - - CleanupStack::PopAndDestroy( pushToStack ); //fs, buffers + // DELETE ALL ARRAYS AND ARRAY CONTENT + // x509CertArray, tempCertArray, certCapaArray, tempCapaArray, fs, buffers + CleanupStack::PopAndDestroy( pushToStack ); BTIC_TRACE_PRINT("UHEAP MARK END"); __UHEAP_MARKEND; @@ -683,8 +717,12 @@ __UHEAP_MARK; TBool storeOK = EFalse; + + RPointerArray updaterExePaths; + CleanupResetAndDestroyPushL( updaterExePaths ); - RPointerArray updaterExePaths; + RPointerArray sisPackages; + CleanupResetAndDestroyPushL( sisPackages ); Swi::RSisRegistrySession sisRegSession; @@ -693,8 +731,6 @@ User::LeaveIfError( sisRegSession.Connect() ); CleanupClosePushL( sisRegSession ); - - RPointerArray sisPackages; // Find installed packages. sisRegSession.InstalledPackagesL( sisPackages ); @@ -778,10 +814,7 @@ } } } - - // Cleanup array. - sisPackages.ResetAndDestroy(); - + if ( entryOpen ) { CleanupStack::PopAndDestroy(); //RSisRegistryEntry @@ -796,8 +829,9 @@ { storeOK = RunUpdaterL( aFs, updaterExePaths ); } - - updaterExePaths.ResetAndDestroy(); + + CleanupStack::PopAndDestroy( 1, &sisPackages ); + CleanupStack::PopAndDestroy( 1, &updaterExePaths ); BTIC_TRACE_PRINT("UHEAP MARK END"); __UHEAP_MARKEND; @@ -827,7 +861,7 @@ { BTIC_TRACE_PRINT("[BOOT INTECRITY CHECK] ValidateProvisonerStoreL --->"); __UHEAP_MARK; - + TBool retOK = EFalse; // installedFiles array owns entry's files. RPointerArray installedFilesArray; @@ -838,6 +872,12 @@ RPointerArray stringArray; HBufC* string = NULL; + CleanupResetAndDestroyPushL( installedFilesArray ); + CleanupResetAndDestroyPushL( foundFilesArray ); + CleanupResetAndDestroyPushL( fileArray ); + CleanupResetAndDestroyPushL( hashArray ); + CleanupResetAndDestroyPushL( stringArray ); + TUint64* capaVector = new( ELeave ) TUint64[KBTICCapaCount]; CleanupArrayDeletePushL( capaVector ); capaVector[0] = KBTIC_TCB; @@ -1050,7 +1090,13 @@ } CleanupStack::PopAndDestroy(); //capaVector - + + CleanupStack::Pop( &stringArray ); + CleanupStack::Pop( &hashArray ); + CleanupStack::Pop( &fileArray ); + CleanupStack::Pop( &foundFilesArray ); + CleanupStack::Pop( &installedFilesArray ); + // Reset only. InstalledFiles array owns buffers. foundFilesArray.Reset(); fileArray.Reset(); @@ -1096,6 +1142,12 @@ RArray capaArray; RPointerArray stringArray; HBufC* string = NULL; + + CleanupResetAndDestroyPushL( installedFilesArray ); + CleanupResetAndDestroyPushL( foundFilesArray ); + CleanupResetAndDestroyPushL( fileArray ); + CleanupResetAndDestroyPushL( hashArray ); + CleanupResetAndDestroyPushL( stringArray ); TUint64* capaVector = new( ELeave ) TUint64[KBTICCapaCount]; CleanupArrayDeletePushL( capaVector ); @@ -1161,7 +1213,13 @@ } CleanupStack::PopAndDestroy(); //capaVector - + + CleanupStack::Pop( &stringArray ); + CleanupStack::Pop( &hashArray ); + CleanupStack::Pop( &fileArray ); + CleanupStack::Pop( &foundFilesArray ); + CleanupStack::Pop( &installedFilesArray ); + // Reset only. InstalledFiles array owns buffers. foundFilesArray.Reset(); fileArray.Reset(); @@ -1392,6 +1450,8 @@ BTIC_TRACE_PRINT("[BOOT INTECRITY CHECK] SearchValidCertificate v2.1 --->"); RPointerArray binaryCertChainArray; + CleanupResetAndDestroyPushL( binaryCertChainArray ); + // Get certificates in binary format. aEntry.CertificateChainsL( binaryCertChainArray ); @@ -1401,7 +1461,8 @@ TBool retVal = EFalse; RPointerArray chainCertArray; - + CleanupResetAndDestroyPushL( chainCertArray ); + // Check all entry's chains for ( TInt chain = 0; chain < chainCount; chain++ ) { @@ -1546,13 +1607,12 @@ if ( retVal ) { break; - } - + } } // FOR LOOP - - binaryCertChainArray.ResetAndDestroy(); - - + + CleanupStack::PopAndDestroy( &chainCertArray ); + CleanupStack::PopAndDestroy( &binaryCertChainArray ); + BTIC_TRACE_PRINT("[BOOT INTECRITY CHECK] SearchValidCertificate v2.1 <---"); return retVal;