kerneltest/f32test/server/t_misc.cpp
branchRCL_3
changeset 42 a179b74831c9
parent 0 a41df078684a
child 43 c1f20ce4abcf
equal deleted inserted replaced
41:0ffb4e86fcc9 42:a179b74831c9
    17 
    17 
    18 #include <f32file.h>
    18 #include <f32file.h>
    19 #include <e32test.h>
    19 #include <e32test.h>
    20 #include "t_server.h"
    20 #include "t_server.h"
    21 
    21 
       
    22 // If there is an NFE media driver present, then because of the way EDeleteNotify requests work,
       
    23 // the data retrieved from a deleted file will not be a buffer full of zero's, but instead a buffer
       
    24 // full of decrypted zero's
       
    25 #define __NFE_MEDIA_DRIVER_PRESENT__
       
    26 
    22 #ifdef __VC32__
    27 #ifdef __VC32__
    23     // Solve compilation problem caused by non-English locale
    28     // Solve compilation problem caused by non-English locale
    24     #pragma setlocale("english")
    29     #pragma setlocale("english")
    25 #endif
    30 #endif
    26 
    31 
    27 GLDEF_D RTest test(_L("T_MISC"));
    32 GLDEF_D RTest test(_L("T_MISC"));
       
    33 
       
    34 const TUint KBufLength = 0x100;
    28 
    35 
    29 LOCAL_C void Test1()
    36 LOCAL_C void Test1()
    30 //
    37 //
    31 // Open, write to and read from a file
    38 // Open, write to and read from a file
    32 //
    39 //
   720 
   727 
   721 void    DoTest14(TInt aDrvNum);
   728 void    DoTest14(TInt aDrvNum);
   722 TInt    CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
   729 TInt    CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
   723 TInt    CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
   730 TInt    CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
   724 TBool   CheckFileContents(RFs& aFs, const TDesC& aFileName);
   731 TBool   CheckFileContents(RFs& aFs, const TDesC& aFileName);
       
   732 #ifndef __NFE_MEDIA_DRIVER_PRESENT__
   725 TBool   CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0);
   733 TBool   CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0);
       
   734 #endif
   726 
   735 
   727 /**
   736 /**
   728 Testing unallocated data initialization vulnerability in RFile
   737 Testing unallocated data initialization vulnerability in RFile
   729 This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag)
   738 This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag)
   730 e.g. XSR NAND
   739 e.g. XSR NAND
   826 
   835 
   827     //-- 1. create an empty file
   836     //-- 1. create an empty file
   828     nRes = CreateEmptyFile(TheFs, fileName, KFileSize);
   837     nRes = CreateEmptyFile(TheFs, fileName, KFileSize);
   829     test(nRes == KErrNone);
   838     test(nRes == KErrNone);
   830 
   839 
       
   840 #ifndef __NFE_MEDIA_DRIVER_PRESENT__	// can't easily check for illegitimate information if drive is encrypted
   831     //-- 1.1  check that this file doesn't contain illegitimate information.
   841     //-- 1.1  check that this file doesn't contain illegitimate information.
   832     nRes = CheckFileContents(TheFs, fileName);
   842     nRes = CheckFileContents(TheFs, fileName);
   833     test(nRes == KErrNone);
   843     test(nRes == KErrNone);
       
   844 #endif
   834 
   845 
   835     //-- 1.2 delete the empty file
   846     //-- 1.2 delete the empty file
   836     nRes = TheFs.Delete(fileName);
   847     nRes = TheFs.Delete(fileName);
   837     test(nRes == KErrNone);
   848     test(nRes == KErrNone);
   838 
   849 
  1236 {
  1247 {
  1237 	TInt    nRes;
  1248 	TInt    nRes;
  1238     RFile   file;
  1249     RFile   file;
  1239 
  1250 
  1240 	//-- create a buffer with some data
  1251 	//-- create a buffer with some data
  1241 	const TUint KBufLength = 0x100;
       
  1242 	TBuf8<KBufLength> buffer;
  1252 	TBuf8<KBufLength> buffer;
  1243 	buffer.SetLength(KBufLength);
  1253 	buffer.SetLength(KBufLength);
  1244 
  1254 
  1245     TUint i;
  1255     TUint i;
  1246 
  1256 
  1287 TInt   CheckFileContents(RFs& aFs, const TDesC& aFileName)
  1297 TInt   CheckFileContents(RFs& aFs, const TDesC& aFileName)
  1288 {
  1298 {
  1289 	TInt    nRes = KErrNone;
  1299 	TInt    nRes = KErrNone;
  1290     RFile   file;
  1300     RFile   file;
  1291 
  1301 
  1292 	const TInt KBufLength = 0x100;
       
  1293 	TBuf8<KBufLength> buffer;
  1302 	TBuf8<KBufLength> buffer;
  1294     buffer.SetLength(0);
  1303     buffer.SetLength(0);
  1295 
  1304 
  1296     //-- open the file
  1305     //-- open the file
  1297     nRes = file.Open(aFs, aFileName, EFileRead);
  1306     nRes = file.Open(aFs, aFileName, EFileRead);
  1309         {
  1318         {
  1310             nRes = KErrNone; //-- read all the file, no illegitimate information found
  1319             nRes = KErrNone; //-- read all the file, no illegitimate information found
  1311             break; //EOF
  1320             break; //EOF
  1312         }
  1321         }
  1313 
  1322 
       
  1323 #ifdef __NFE_MEDIA_DRIVER_PRESENT__
       
  1324 		// check the buffer doesn't contain the same pattern written to it by CreateStuffedFile()
       
  1325 		TUint i;
       
  1326 		for(i = 0; i < KBufLength; i++)
       
  1327 			if (buffer[i] != static_cast<TUint8> (i))
       
  1328 				break;
       
  1329 		if (i == KBufLength)
       
  1330 			{
       
  1331             nRes = KErrCorrupt; //-- indicate that the read buffer contains illegitimate information
       
  1332             break; //-- comment this out if you need a full dump of the file
       
  1333 			}
       
  1334 #else
  1314         //-- check if the buffer contains only allowed data (RAM page initialisation data, etc. e.g. 0x00, 0xff, 0x03, 0xcc)
  1335         //-- check if the buffer contains only allowed data (RAM page initialisation data, etc. e.g. 0x00, 0xff, 0x03, 0xcc)
  1315         if(!CheckBufferContents(buffer, nFilePos))
  1336         if(!CheckBufferContents(buffer, nFilePos))
  1316         {
  1337         {
  1317             test.Printf(_L("\nCheckFileContents failed ! The file contains illegitimate information!\n"));
  1338             test.Printf(_L("\nCheckFileContents failed ! The file contains illegitimate information!\n"));
  1318             nRes = KErrCorrupt; //-- indicate that the read buffer contains illegitimate information
  1339             nRes = KErrCorrupt; //-- indicate that the read buffer contains illegitimate information
  1319             break; //-- comment this out if you need a full dump of the file
  1340             break; //-- comment this out if you need a full dump of the file
  1320         }
  1341         }
       
  1342 #endif
  1321 
  1343 
  1322         nFilePos+=buffer.Length();
  1344         nFilePos+=buffer.Length();
  1323     }
  1345     }
  1324 
  1346 
  1325     file.Close();
  1347     file.Close();