]> git.saurik.com Git - wxWidgets.git/commitdiff
check that wxString is valid before dumping it
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 20 Jul 2005 15:32:07 +0000 (15:32 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 20 Jul 2005 15:32:07 +0000 (15:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34895 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/debughlp.cpp

index 8075dd672a85b53a4181becbb74cad72fbfe1c6a..cd8e486616ab2101760f19930bb3c65e9cd12788 100644 (file)
@@ -399,10 +399,20 @@ wxDbgHelpDLL::DumpUDT(PSYMBOL_INFO pSym, void *pVariable, unsigned level)
     {
         wxString *ps = (wxString *)pVariable;
 
-        // take care to use c_str() here as otherwise we might hit an assert in
-        // wxString code if it is currently locked for writing (i.e. we're
-        // between GetWriteBuf() and UngetWriteBuf() calls)
-        s << _T("(\"") << ps->c_str() << _T(")\"");
+        // we can't just dump wxString directly as it could be corrupted or
+        // invalid and it could also be locked for writing (i.e. if we're
+        // between GetWriteBuf() and UngetWriteBuf() calls) and assert when we
+        // try to access it contents using public methods, so instead use our
+        // knowledge of its internals
+        const wxChar *p = ps->data();
+        wxStringData *data = (wxStringData *)p - 1;
+        if ( ::IsBadReadPtr(data, sizeof(wxStringData)) ||
+                ::IsBadReadPtr(p, sizeof(wxChar *)*data->nAllocLength) )
+        {
+            p = _T("???");
+        }
+
+        s << _T("(\"") << p << _T(")\"");
     }
     else // any other UDT
 #endif // !wxUSE_STL