CVS: winex/dlls/dbghelp minidump.c,1.7,1.8

[email protected] 14 Dec 2007 19:14:16 -0000
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/dlls/dbghelp minidump.c,1.7,1.8Update of /var/lib/cvsd/cvsroot/winex/dlls/dbghelp
In directory agravaine:/tmp/cvs-serv12434/dlls/dbghelp

Modified Files:
	minidump.c 
Log Message:
fixed gigantic minidump files

- added some error checking on retrieving the value of ESP when saving out thread stacks.




Index: minidump.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/dlls/dbghelp/minidump.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- minidump.c	27 Nov 2007 18:37:48 -0000	1.7
+++ minidump.c	14 Dec 2007 19:14:14 -0000	1.8
@@ -120,20 +120,50 @@
     {
 #ifdef __i386__
         /* limiting the stack dumping to the size actually used */
-        if (ctx->Esp)
-            mmd->StartOfMemoryRange = (ctx->Esp - 4);
+        if (ctx->Esp){
+
+            /* make sure ESP is within the established range of the stack.  It could have
+               been clobbered by whatever caused the original exception. */
+            if (ctx->Esp - 4 < (ULONG_PTR)tib.StackLimit || ctx->Esp - 4 > (ULONG_PTR)tib.StackBase)
+                mmd->StartOfMemoryRange = (ULONG_PTR)tib.StackLimit;
+
+            else
+                mmd->StartOfMemoryRange = (ctx->Esp - 4);
+        }
+
         else
             mmd->StartOfMemoryRange = (ULONG_PTR)tib.StackLimit;
+
 #elif defined(__powerpc__)
-        if (ctx->Iar)
-            mmd->StartOfMemoryRange = ctx->Iar - 4;
+        if (ctx->Iar){
+   
+            /* make sure ESP is within the established range of the stack.  It could have
+               been clobbered by whatever caused the original exception. */
+            if (ctx->Iar - 4 < (ULONG_PTR)tib.StackLimit || ctx->Iar - 4 > (ULONG_PTR)tib.StackBase)
+                mmd->StartOfMemoryRange = (ULONG_PTR)tib.StackLimit;
+
+            else
+                mmd->StartOfMemoryRange = (ctx->Iar - 4);
+        }
+
         else
             mmd->StartOfMemoryRange = (ULONG_PTR)tib.StackLimit;
+
 #elif defined(__x86_64__)
-        if (ctx->Rsp)
-            mmd->StartOfMemoryRange = (ctx->Rsp - 8);
+        if (ctx->Rsp){
+
+            /* make sure ESP is within the established range of the stack.  It could have
+               been clobbered by whatever caused the original exception. */
+            if (ctx->Rsp - 8 < (ULONG_PTR)tib.StackLimit || ctx->Rsp - 8 > (ULONG_PTR)tib.StackBase)
+                mmd->StartOfMemoryRange = (ULONG_PTR)tib.StackLimit;
+
+            else
+                mmd->StartOfMemoryRange = (ctx->Rsp - 8);
+        }
+
         else
             mmd->StartOfMemoryRange = (ULONG_PTR)tib.StackLimit;
+
 #else
 #error unsupported CPU
 #endif