Bug 501605: address review comments from comment 163, a=beltzner
authorGavin Sharp <gavin@mozilla.com>
Wed, 15 Jul 2009 01:39:35 -0400
changeset 26066 b91c9ee69e6ef73c54ada2aa2e97a7055c24d416
parent 26065 d40be78ef5152a59ef6c31a8ee5dce3c44fd9e98
child 26067 a97db942191c8d2a7830fd390042fbeb99e6674b
child 26072 3786c13f6fc0129badd195941800b6f8436917eb
push id1773
push usergsharp@mozilla.com
push dateWed, 15 Jul 2009 05:39:42 +0000
reviewersbeltzner
bugs501605
milestone1.9.1.1pre
Bug 501605: address review comments from comment 163, a=beltzner
security/nss/lib/freebl/win_rand.c
--- a/security/nss/lib/freebl/win_rand.c
+++ b/security/nss/lib/freebl/win_rand.c
@@ -136,44 +136,44 @@ typedef PRInt32 (* Handler)(const PRUnic
 #define MAX_DEPTH 2
 #define MAX_FOLDERS 4
 #define MAX_FILES 1024
 
 static void
 EnumSystemFilesInFolder(Handler func, PRUnichar* szSysDir, int maxDepth) 
 {
     int                 iContinue;
-    unsigned int        iFolders  = 0;
-    unsigned int        iFiles    = 0;
+    unsigned int        uFolders  = 0;
+    unsigned int        uFiles    = 0;
     HANDLE              lFindHandle;
     WIN32_FIND_DATAW    fdData;
     PRUnichar           szFileName[_MAX_PATH];
 
     if (maxDepth < 0)
     	return;
-    // append *.* so we actually look for files. this will not overflow
+    // append *.* so we actually look for files.
     _snwprintf(szFileName, _MAX_PATH, L"%s\\*.*", szSysDir);
 
     lFindHandle = FindFirstFileW(szFileName, &fdData);
     if (lFindHandle == INVALID_HANDLE_VALUE)
         return;
     do {
 	iContinue = 1;
 	if (wcscmp(fdData.cFileName, L".") == 0 ||
             wcscmp(fdData.cFileName, L"..") == 0) {
 	    // skip "." and ".."
 	} else {
 	    // pass the full pathname to the callback
 	    _snwprintf(szFileName, _MAX_PATH, L"%s\\%s", szSysDir, 
 		       fdData.cFileName);
 	    if (fdData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
-		if (++iFolders <= MAX_FOLDERS)
+		if (++uFolders <= MAX_FOLDERS)
 		    EnumSystemFilesInFolder(func, szFileName, maxDepth - 1);
 	    } else {
-		iContinue = (++iFiles <= MAX_FILES) && !(*func)(szFileName);
+		iContinue = (++uFiles <= MAX_FILES) && !(*func)(szFileName);
 	    }
 	}
 	if (iContinue)
 	    iContinue = FindNextFileW(lFindHandle, &fdData);
     } while (iContinue);
     FindClose(lFindHandle);
 }
 
@@ -211,17 +211,16 @@ CountFiles(const PRUnichar *file)
     dwNumFiles++;
     return 0;
 }
 
 static int
 ReadSingleFile(const char *filename)
 {
     PRFileDesc *    file;
-    int             nBytes;
     unsigned char   buffer[1024];
 
     file = PR_Open(filename, PR_RDONLY, 0);
     if (file != NULL) {
 	while (PR_Read(file, buffer, sizeof buffer) > 0)
 	    ;
         PR_Close(file);
     }
@@ -421,19 +420,20 @@ void RNG_FileForRNG(const char *filename
  * The Windows CE and Windows Mobile FIPS Security Policy, page 13,
  * (http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140sp/140sp825.pdf)
  * says CeGenRandom is the right function to call for creating a seed
  * for a random number generator.
  */
 size_t RNG_SystemRNG(void *dest, size_t maxLen)
 {
     size_t bytes = 0;
+    usedWindowsPRNG = PR_FALSE;
     if (CeGenRandom(maxLen, dest)) {
-	    bytes = maxLen;
-	    usedWindowsPRNG = PR_TRUE;
+	bytes = maxLen;
+	usedWindowsPRNG = PR_TRUE;
     }
     if (bytes == 0) {
 	bytes = rng_systemFromNoise(dest,maxLen);
     }
     return bytes;
 }