Bug 1342349 - Fix out-of-bounds access in GetInfoForSelf. r=mstange
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Fri, 24 Feb 2017 17:42:43 +0000
changeset 373828 aab0b3a45dae09c44e035628463759dc9b6948a7
parent 373827 473d5e1d8e07be471973b5313e87e52faded074b
child 373829 525fc9bb16c79203da9ecd65db36024af47cdb32
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1342349
milestone54.0a1
Bug 1342349 - Fix out-of-bounds access in GetInfoForSelf. r=mstange
tools/profiler/core/shared-libraries-win32.cc
--- a/tools/profiler/core/shared-libraries-win32.cc
+++ b/tools/profiler/core/shared-libraries-win32.cc
@@ -123,30 +123,30 @@ SharedLibraryInfo SharedLibraryInfo::Get
     }
     modulesNum = modulesSize / sizeof(HMODULE);
     hMods = mozilla::MakeUnique<HMODULE[]>(modulesNum);
     if (!EnumProcessModules(hProcess, hMods.get(), modulesNum * sizeof(HMODULE), &modulesSize)) {
       return sharedLibraryInfo;
     }
   }
 
-  for (unsigned int i = 0; i <= modulesNum; i++) {
+  for (const auto& hMod : hMods) {
     nsID pdbSig;
     uint32_t pdbAge;
     nsAutoString pdbNameStr;
     char *pdbName = NULL;
     std::string breakpadId;
     WCHAR modulePath[MAX_PATH + 1];
 
-    if (!GetModuleFileNameEx(hProcess, hMods[i], modulePath, sizeof(modulePath) / sizeof(WCHAR))) {
+    if (!GetModuleFileNameEx(hProcess, hMod, modulePath, sizeof(modulePath) / sizeof(WCHAR))) {
       continue;
     }
 
     MODULEINFO module = {0};
-    if (!GetModuleInformation(hProcess, hMods[i], &module, sizeof(MODULEINFO))) {
+    if (!GetModuleInformation(hProcess, hMod, &module, sizeof(MODULEINFO))) {
       continue;
     }
 
     // Load the module again to make sure that its handle will remain remain
     // valid as we attempt to read the PDB information from it.  We load the
     // DLL as a datafile so that if the module actually gets unloaded between
     // the call to EnumProcessModules and the following LoadLibraryEx, we don't
     // end up running the now newly loaded module's DllMain function.  If the