]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't crash when input is empty in wxFileConfig(wxInputStream) ctor.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 23 Jan 2010 13:22:14 +0000 (13:22 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 23 Jan 2010 13:22:14 +0000 (13:22 +0000)
Fix crash due to dereferencing a NULL pointer when the input buffer in
wxFileConfig ctor is empty.

Closes #11636.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63228 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/common/fileconf.cpp
tests/config/fileconf.cpp

index e99cbdf2f36820c2f313ec47b9de9fbe9c520447..a774275fee178cad6aca713f17f4f8336e964063 100644 (file)
@@ -436,6 +436,7 @@ All:
 - Added wxHttp::GetCookie and wxHttp::HasCookies (dodge).
 - Added support for unique volume names to wxFileName (Neno Ganchev).
 - Correct bugs when using wxTextInputStream with wxConvAuto (Leon Buikstra).
+- Don't crash when input is empty in wxFileConfig ctor (Lukasz Michalski).
 
 Unix:
 
index 42c8b950ed6f2497976914092d1840cadf93da89..286c03955da6e39169bacf87d81528ca5111e136 100644 (file)
@@ -469,32 +469,35 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, const wxMBConv& conv)
     cbuf = wxCharBuffer::CreateNonOwned((char *)buf.GetData(), buf.GetDataLen());
 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
 
-
-    // now break it into lines
-    wxMemoryText memText;
-    for ( const wxChar *s = cbuf; ; ++s )
+    // parse the input contents if there is anything to parse
+    if ( cbuf )
     {
-        const wxChar *e = s;
-        while ( *e != '\0' && *e != '\n' && *e != '\r' )
-            ++e;
+        // now break it into lines
+        wxMemoryText memText;
+        for ( const wxChar *s = cbuf; ; ++s )
+        {
+            const wxChar *e = s;
+            while ( *e != '\0' && *e != '\n' && *e != '\r' )
+                ++e;
 
-        // notice that we throw away the original EOL kind here, maybe we
-        // should preserve it?
-        if ( e != s )
-            memText.AddLine(wxString(s, e));
+            // notice that we throw away the original EOL kind here, maybe we
+            // should preserve it?
+            if ( e != s )
+                memText.AddLine(wxString(s, e));
 
-        if ( *e == '\0' )
-            break;
+            if ( *e == '\0' )
+                break;
 
-        // skip the second EOL byte if it's a DOS one
-        if ( *e == '\r' && e[1] == '\n' )
-            ++e;
+            // skip the second EOL byte if it's a DOS one
+            if ( *e == '\r' && e[1] == '\n' )
+                ++e;
 
-        s = e;
-    }
+            s = e;
+        }
 
-    // Finally we can parse it all.
-    Parse(memText, true /* local */);
+        // Finally we can parse it all.
+        Parse(memText, true /* local */);
+    }
 
     SetRootPath();
     ResetDirty();
index d1cd56b40d2157ea8f08e0b5923975c734d747e0..4a354479b992bc5f9ed5a189c84c7f3164971849 100644 (file)
@@ -81,6 +81,7 @@ private:
         CPPUNIT_TEST( DeleteAndRecreateGroup );
         CPPUNIT_TEST( AddToExistingRoot );
         CPPUNIT_TEST( ReadNonExistent );
+        CPPUNIT_TEST( ReadEmpty );
     CPPUNIT_TEST_SUITE_END();
 
     void Path();
@@ -103,6 +104,7 @@ private:
     void DeleteAndRecreateGroup();
     void AddToExistingRoot();
     void ReadNonExistent();
+    void ReadEmpty();
 
 
     static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
@@ -649,5 +651,13 @@ void FileConfigTestCase::ReadNonExistent()
     CPPUNIT_ASSERT( !fc.Read("URL", &url) );
 }
 
+void FileConfigTestCase::ReadEmpty()
+{
+    static const char *confTest = "";
+
+    wxStringInputStream sis(confTest);
+    wxFileConfig fc(sis);
+}
+
 #endif // wxUSE_FILECONFIG