Bug 417903. Don't crash if _SymGetLineFromAddr64 fails. r=benjamin,a=beltzner
authorroc+@cs.cmu.edu
Sun, 24 Feb 2008 17:16:41 -0800
changeset 12185 54c677ce3f7a10b43e1b250866326996ef1e76b2
parent 12184 26ef9bb0bc111fddf1fb4a74c4ec78018b25f3e1
child 12186 7b56d0a7c841f6ccbc493ecb95f8b60be78de6d1
push idunknown
push userunknown
push dateunknown
reviewersbenjamin, beltzner
bugs417903
milestone1.9b4pre
Bug 417903. Don't crash if _SymGetLineFromAddr64 fails. r=benjamin,a=beltzner
xpcom/base/nsStackWalk.cpp
--- a/xpcom/base/nsStackWalk.cpp
+++ b/xpcom/base/nsStackWalk.cpp
@@ -904,16 +904,20 @@ BOOL SymGetModuleInfoEspecial64(HANDLE a
     /*
      * If we got module info, we may attempt line info as well.
      * We will not report failure if this does not work.
      */
     if (FALSE != retval && nsnull != aLineInfo && nsnull != _SymGetLineFromAddr64) {
         DWORD displacement = 0;
         BOOL lineRes = FALSE;
         lineRes = _SymGetLineFromAddr64(aProcess, aAddr, &displacement, aLineInfo);
+        if (!lineRes) {
+            // Clear out aLineInfo to indicate that it's not valid
+            memset(aLineInfo, 0, sizeof(*aLineInfo));
+        }
     }
 
     return retval;
 }
 #endif
 
 HANDLE
 GetCurrentPIDorHandle()
@@ -979,19 +983,22 @@ NS_DescribeCodeAddress(void *aPC, nsCode
         IMAGEHLP_LINE64 lineInfo;
         BOOL modInfoRes;
         modInfoRes = SymGetModuleInfoEspecial64(myProcess, addr, &modInfo, &lineInfo);
 
         if (modInfoRes) {
             PL_strncpyz(aDetails->library, modInfo.ModuleName,
                         sizeof(aDetails->library));
             aDetails->loffset = (char*) aPC - (char*) modInfo.BaseOfImage;
-            PL_strncpyz(aDetails->filename, lineInfo.FileName,
-                        sizeof(aDetails->filename));
-            aDetails->lineno = lineInfo.LineNumber;
+            
+            if (lineInfo.FileName) {
+                PL_strncpyz(aDetails->filename, lineInfo.FileName,
+                            sizeof(aDetails->filename));
+                aDetails->lineno = lineInfo.LineNumber;
+            }
         }
 
         ULONG64 buffer[(sizeof(SYMBOL_INFO) +
           MAX_SYM_NAME*sizeof(TCHAR) + sizeof(ULONG64) - 1) / sizeof(ULONG64)];
         PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
         pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
         pSymbol->MaxNameLen = MAX_SYM_NAME;