Messy diff

Johan Gill johane at lysator.liu.se
Mon Oct 15 14:40:30 CDT 2001


I found that there were problems with --debugmsg=+relay when hitting a
function call with an invalid pointer as parameter. wine_dbgstr_an() would
try to dereference the pointer, resulting in a crash.

Here's a patch for it. If anything is done the wrong way, please comment
on it.

/Johan Gill, johane at lysator.liu.se

-------------- next part --------------
Index: wine/dlls/ntdll/debugtools.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/debugtools.c,v
retrieving revision 1.10
diff -u -r1.10 debugtools.c
--- wine/dlls/ntdll/debugtools.c	2001/07/17 00:56:37	1.10
+++ wine/dlls/ntdll/debugtools.c	2001/10/15 17:48:39
@@ -10,6 +10,7 @@
 #include <ctype.h>
 
 #include "debugtools.h"
+#include "wine/exception.h"
 #include "thread.h"
 #include "winbase.h"
 #include "winnt.h"
@@ -72,6 +73,15 @@
 /***********************************************************************
  *		wine_dbgstr_an (NTDLL.@)
  */
+
+/* filter for page-fault exceptions */
+static WINE_EXCEPTION_FILTER(page_fault)
+{
+    if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
+	return EXCEPTION_EXECUTE_HANDLER;
+    return EXCEPTION_CONTINUE_SEARCH;
+}
+
 const char *wine_dbgstr_an( const char *src, int n )
 {
     char *dst, *res;
@@ -87,36 +97,43 @@
     else if (n > 200) n = 200;
     dst = res = gimme1 (n * 4 + 6);
     *dst++ = '"';
-    while (n-- > 0 && *src)
-    {
-        unsigned char c = *src++;
-        switch (c)
+    __TRY {
+	while (n-- > 0 && *src)
         {
-        case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
-        case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
-        case '\t': *dst++ = '\\'; *dst++ = 't'; break;
-        case '"': *dst++ = '\\'; *dst++ = '"'; break;
-        case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
-        default:
-            if (c >= ' ' && c <= 126)
-                *dst++ = c;
-            else
-            {
-                *dst++ = '\\';
-                *dst++ = '0' + ((c >> 6) & 7);
-                *dst++ = '0' + ((c >> 3) & 7);
-                *dst++ = '0' + ((c >> 0) & 7);
-            }
-        }
+	    unsigned char c = *src++;
+	    switch (c)
+	    {
+	    case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
+	    case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
+	    case '\t': *dst++ = '\\'; *dst++ = 't'; break;
+	    case '"': *dst++ = '\\'; *dst++ = '"'; break;
+	    case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
+	    default:
+		if (c >= ' ' && c <= 126)
+		    *dst++ = c;
+		else
+		    {
+			*dst++ = '\\';
+			*dst++ = '0' + ((c >> 6) & 7);
+			*dst++ = '0' + ((c >> 3) & 7);
+			*dst++ = '0' + ((c >> 0) & 7);
+		    }
+	    }
+	}
+	*dst++ = '"';
+	if (*src)
+	{
+	    *dst++ = '.';
+	    *dst++ = '.';
+	    *dst++ = '.';
+	}
+	*dst++ = '\0';
     }
-    *dst++ = '"';
-    if (*src)
-    {
-        *dst++ = '.';
-        *dst++ = '.';
-        *dst++ = '.';
+    __EXCEPT(page_fault) {
+	release( dst );
+	return "(invalid)";
     }
-    *dst++ = '\0';
+    __ENDTRY
     release( dst );
     return res;
 }


More information about the wine-devel mailing list