# HG changeset patch # User Dremov Kirill (Nokia-D-MSW/Tampere) # Date 1276072569 -10800 # Node ID b6ab70c1385f26eb000b3a3af95e21a2b622c2fb # Parent fcc16690f446445cfc03747efbcea28fe1f1d26e Revision: 201023 Kit: 2010123 diff -r fcc16690f446 -r b6ab70c1385f loggingservices/filelogger/SSVR/FLOGSVR.CPP --- a/loggingservices/filelogger/SSVR/FLOGSVR.CPP Tue May 25 14:35:19 2010 +0300 +++ b/loggingservices/filelogger/SSVR/FLOGSVR.CPP Wed Jun 09 11:36:09 2010 +0300 @@ -1,4 +1,4 @@ -// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of "Eclipse Public License v1.0" @@ -26,6 +26,11 @@ */ const TInt KOpenLogFilesGranularity=5; +/* Internal error. Use positive number to ensure no conflict with other error code + Indicate that client message has panic'ed and should not be completed. +*/ +const TInt KErrMessagePanic = 1; + /** panics for log client @@ -268,7 +273,10 @@ { TRAPD(ret,DispatchMessageL(aMessage)); - aMessage.Complete(ret); + if (ret!=KErrMessagePanic) + { + aMessage.Complete(ret); + } } void CFileLogSession::DispatchMessageL(const RMessage2& aMessage) @@ -281,13 +289,24 @@ TLogFile log; TPckg logPckg(log); aMessage.ReadL(0,logPckg); - __ASSERT_ALWAYS(log.Directory().Length()!=0,aMessage.Panic(KFLoggerServerName,ELogDirectoryNameDoesNotExist)); - __ASSERT_ALWAYS(log.Name().Length()!=0,aMessage.Panic(KFLoggerServerName,ELogFileNameDoesNotExist)); + if (log.Directory().Length()<=0) + { + aMessage.Panic(KFLoggerServerName,ELogDirectoryNameDoesNotExist); + User::Leave(KErrMessagePanic); + } + + if (log.Name().Length()<=0) + { + aMessage.Panic(KFLoggerServerName,ELogFileNameDoesNotExist); + User::Leave(KErrMessagePanic); + } // TBuf8 buf; TBuf8<1600> buf; if (func==EWriteLog || func==ECreateWriteAndCloseLog) + { aMessage.ReadL(1,buf); + } switch (func) { diff -r fcc16690f446 -r b6ab70c1385f persistentstorage/dbms/ustor/US_FILE.CPP --- a/persistentstorage/dbms/ustor/US_FILE.CPP Tue May 25 14:35:19 2010 +0300 +++ b/persistentstorage/dbms/ustor/US_FILE.CPP Wed Jun 09 11:36:09 2010 +0300 @@ -98,7 +98,7 @@ default: __LEAVE(KErrNotSupported); case TDbFormat::ECreate: - store=CPermanentFileStore::CreateL(iFs,aName,EFileRead|EFileWrite); + store=CPermanentFileStore::CreateL(iFs,aName,EFileRead|EFileWrite); break; case TDbFormat::EReplace: store=CPermanentFileStore::ReplaceL(iFs,aName,EFileRead|EFileWrite); @@ -143,7 +143,7 @@ __ASSERT(!iName); // check construction phase // iName=aName.AllocL(); - const TUint mode=aMode==TDbFormat::EReadOnly ? EFileShareReadersOnly : EFileWrite; + TUint mode=aMode==TDbFormat::EReadOnly ? EFileShareReadersOnly : EFileWrite; CFileStore* store=CPermanentFileStore::OpenL(iFs,*iName,mode); iStore=store; CDbStoreDatabase::RestoreL(DatabaseIdL(store->Root())); diff -r fcc16690f446 -r b6ab70c1385f persistentstorage/dbms/ustor/US_TABLE.CPP --- a/persistentstorage/dbms/ustor/US_TABLE.CPP Tue May 25 14:35:19 2010 +0300 +++ b/persistentstorage/dbms/ustor/US_TABLE.CPP Wed Jun 09 11:36:09 2010 +0300 @@ -611,7 +611,9 @@ TInt size; rec=ReadCardinality(rec,size); size<<=2; - if(size < 0) + + //If such huge allocation is requested(KMaxTInt/2), it is highly likely the file is corrupt + if((size < 0) || (size >= KMaxTInt/2)) { aRow.SetSize(0); __LEAVE(KErrCorrupt); diff -r fcc16690f446 -r b6ab70c1385f persistentstorage/sql/OsLayer/FileBuf64.cpp --- a/persistentstorage/sql/OsLayer/FileBuf64.cpp Tue May 25 14:35:19 2010 +0300 +++ b/persistentstorage/sql/OsLayer/FileBuf64.cpp Wed Jun 09 11:36:09 2010 +0300 @@ -1107,9 +1107,9 @@ const TInt KDefaultPageSize = 1024;//The journal header size is equal to 512 bytes, so it is not easy //to detect the 512 bytes page size. - __FBUF64_ASSERT(aRwDataLength >= 0, EFBufPanicRwDataLength); + __FBUF64_ASSERT(aRwDataLength > 0, EFBufPanicRwDataLength); __FILEBUF64_INVARIANT(); - if(iOptimized || aRwDataLength == 0) + if(iOptimized) { __FILEBUF64_INVARIANT(); return KErrNone; diff -r fcc16690f446 -r b6ab70c1385f persistentstorage/sql/TEST/t_sqlapi.cpp --- a/persistentstorage/sql/TEST/t_sqlapi.cpp Tue May 25 14:35:19 2010 +0300 +++ b/persistentstorage/sql/TEST/t_sqlapi.cpp Wed Jun 09 11:36:09 2010 +0300 @@ -299,22 +299,24 @@ { maxFileName = KMaxFileName -150;//The test will panic in PlatSim when the file name is too long. This line should be removed when platsim team fixes the file system defect. } - HBufC* dbPath = HBufC::NewLC(maxFileName); + HBufC* dbPath = HBufC::New(maxFileName); + TEST(dbPath != NULL); + TPtr dbPathPtr = dbPath->Des(); _LIT(KExt, ".DB"); - dbPath->Des().Copy(_L("C:")); - dbPath->Des().Append(KSecureUid.Name()); - TInt len = maxFileName + 1 - (dbPath->Length() + KExt().Length() + privatePath.Length()); + dbPathPtr.Copy(_L("C:")); + dbPathPtr.Append(KSecureUid.Name()); + TInt len = maxFileName + 1 - (dbPathPtr.Length() + KExt().Length() + privatePath.Length()); while(--len) { - dbPath->Des().Append(TChar('A')); + dbPathPtr.Append(TChar('A')); } - dbPath->Des().Append(KExt); - TEST(dbPath->Length() == (maxFileName - privatePath.Length())); - rc = db.Create(dbPath->Des(), securityPolicy); + dbPathPtr.Append(KExt); + TEST(dbPathPtr.Length() == (maxFileName - privatePath.Length())); + rc = db.Create(dbPathPtr, securityPolicy); TEST2(rc, KErrNone); db.Close(); - rc2 = RSqlDatabase::Delete(dbPath->Des()); + rc2 = RSqlDatabase::Delete(dbPathPtr); TEST2(rc2, KErrNone); // Private database with config @@ -330,19 +332,20 @@ //Public shared database file on an existing drive (C:). //Very long database file name. - dbPath->Des().Copy(_L("C:\\TEST\\D")); - len = maxFileName + 1 - (dbPath->Length() + KExt().Length()); + dbPathPtr.Copy(_L("C:\\TEST\\D")); + len = maxFileName + 1 - (dbPathPtr.Length() + KExt().Length()); while(--len) { - dbPath->Des().Append(TChar('A')); + dbPathPtr.Append(TChar('A')); } - dbPath->Des().Append(KExt); - TEST(dbPath->Length() == maxFileName); - rc = db.Create(dbPath->Des()); + dbPathPtr.Append(KExt); + TEST(dbPathPtr.Length() == maxFileName); + rc = db.Create(dbPathPtr); db.Close(); - rc2 = RSqlDatabase::Delete(dbPath->Des()); + rc2 = RSqlDatabase::Delete(dbPathPtr); - CleanupStack::PopAndDestroy(dbPath); + delete dbPath; + TEST2(rc, KErrNone); TEST2(rc2, KErrNone); diff -r fcc16690f446 -r b6ab70c1385f persistentstorage/sql/TEST/t_sqlfilebuf64.cpp --- a/persistentstorage/sql/TEST/t_sqlfilebuf64.cpp Tue May 25 14:35:19 2010 +0300 +++ b/persistentstorage/sql/TEST/t_sqlfilebuf64.cpp Wed Jun 09 11:36:09 2010 +0300 @@ -50,6 +50,10 @@ EOomTempTest }; +//Used in read/write OOM tests +const TUint8 KChar = 'A'; +const TInt KPageSize = 32768; + /////////////////////////////////////////////////////////////////////////////////////// void DeleteTestFiles() @@ -1118,6 +1122,140 @@ TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt); } +/** +@SYMTestCaseID PDS-SQL-UT-4207 +@SYMTestCaseDesc RFileBuf64::Write() OOM test. + The test calls RFileBuf64:Write() in an OOM + simulation loop and verifies that no memory is leaked. + The test also check that RFileBuf::DoSetCapacity() correctly operates in + "out of memory" situation. +@SYMTestActions RFileBuf64::Write() OOM test. +@SYMTestExpectedResults Test must not fail +@SYMTestPriority High +@SYMDEF 380056 +*/ +void WriteOomTest() + { + HBufC8* databuf = HBufC8::New(KPageSize); + TEST(databuf != NULL); + TPtr8 dataptr = databuf->Des(); + dataptr.SetLength(KPageSize); + dataptr.Fill(TChar(KChar)); + + TInt err = KErrNoMemory; + TInt failingAllocationNo = 0; + TheTest.Printf(_L("Iteration:\r\n")); + while(err == KErrNoMemory) + { + TheTest.Printf(_L(" %d"), ++failingAllocationNo); + + (void)TheFs.Delete(KTestFile); + + MarkHandles(); + MarkAllocatedCells(); + + __UHEAP_MARK; + __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate); + + const TInt KDefaultBufCapacity = 1024; + RFileBuf64 fbuf(KDefaultBufCapacity); + err = fbuf.Create(TheFs, KTestFile, EFileWrite | EFileRead); + if(err == KErrNone) + { + err = fbuf.Write(0LL, dataptr); + } + fbuf.Close(); + + __UHEAP_RESET; + __UHEAP_MARKEND; + + CheckAllocatedCells(); + CheckHandles(); + } + TEST2(err, KErrNone); + RFile64 file; + err = file.Open(TheFs, KTestFile, EFileRead); + TEST2(err, KErrNone); + dataptr.Zero(); + err = file.Read(dataptr); + TEST2(err, KErrNone); + file.Close(); + TEST2(dataptr.Length(), KPageSize); + for(TInt i=0;iDes(); + + TInt err = KErrNoMemory; + TInt failingAllocationNo = 0; + TheTest.Printf(_L("Iteration:\r\n")); + while(err == KErrNoMemory) + { + TheTest.Printf(_L(" %d"), ++failingAllocationNo); + + MarkHandles(); + MarkAllocatedCells(); + + __UHEAP_MARK; + __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate); + + const TInt KDefaultBufCapacity = 1024; + RFileBuf64 fbuf(KDefaultBufCapacity); + err = fbuf.Open(TheFs, KTestFile, EFileRead); + if(err == KErrNone) + { + err = fbuf.Read(0LL, dataptr); + } + fbuf.Close(); + + __UHEAP_RESET; + __UHEAP_MARKEND; + + CheckAllocatedCells(); + CheckHandles(); + } + TEST2(err, KErrNone); + RFile64 file; + err = file.Open(TheFs, KTestFile, EFileRead); + TEST2(err, KErrNone); + dataptr.Zero(); + err = file.Read(dataptr); + TEST2(err, KErrNone); + file.Close(); + TEST2(dataptr.Length(), KPageSize); + for(TInt i=0;i