Don't crash when input is empty in wxFileConfig(wxInputStream) ctor.

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
This commit is contained in:
Vadim Zeitlin
2010-01-23 13:22:14 +00:00
parent 03cc29918f
commit 975fb32b5c
3 changed files with 34 additions and 20 deletions

View File

@@ -436,6 +436,7 @@ All:
- Added wxHttp::GetCookie and wxHttp::HasCookies (dodge). - Added wxHttp::GetCookie and wxHttp::HasCookies (dodge).
- Added support for unique volume names to wxFileName (Neno Ganchev). - Added support for unique volume names to wxFileName (Neno Ganchev).
- Correct bugs when using wxTextInputStream with wxConvAuto (Leon Buikstra). - Correct bugs when using wxTextInputStream with wxConvAuto (Leon Buikstra).
- Don't crash when input is empty in wxFileConfig ctor (Lukasz Michalski).
Unix: Unix:

View File

@@ -469,7 +469,9 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, const wxMBConv& conv)
cbuf = wxCharBuffer::CreateNonOwned((char *)buf.GetData(), buf.GetDataLen()); cbuf = wxCharBuffer::CreateNonOwned((char *)buf.GetData(), buf.GetDataLen());
#endif // wxUSE_UNICODE/!wxUSE_UNICODE #endif // wxUSE_UNICODE/!wxUSE_UNICODE
// parse the input contents if there is anything to parse
if ( cbuf )
{
// now break it into lines // now break it into lines
wxMemoryText memText; wxMemoryText memText;
for ( const wxChar *s = cbuf; ; ++s ) for ( const wxChar *s = cbuf; ; ++s )
@@ -495,6 +497,7 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, const wxMBConv& conv)
// Finally we can parse it all. // Finally we can parse it all.
Parse(memText, true /* local */); Parse(memText, true /* local */);
}
SetRootPath(); SetRootPath();
ResetDirty(); ResetDirty();

View File

@@ -81,6 +81,7 @@ private:
CPPUNIT_TEST( DeleteAndRecreateGroup ); CPPUNIT_TEST( DeleteAndRecreateGroup );
CPPUNIT_TEST( AddToExistingRoot ); CPPUNIT_TEST( AddToExistingRoot );
CPPUNIT_TEST( ReadNonExistent ); CPPUNIT_TEST( ReadNonExistent );
CPPUNIT_TEST( ReadEmpty );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
void Path(); void Path();
@@ -103,6 +104,7 @@ private:
void DeleteAndRecreateGroup(); void DeleteAndRecreateGroup();
void AddToExistingRoot(); void AddToExistingRoot();
void ReadNonExistent(); void ReadNonExistent();
void ReadEmpty();
static wxString ChangePath(wxFileConfig& fc, const wxChar *path) static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
@@ -649,5 +651,13 @@ void FileConfigTestCase::ReadNonExistent()
CPPUNIT_ASSERT( !fc.Read("URL", &url) ); CPPUNIT_ASSERT( !fc.Read("URL", &url) );
} }
void FileConfigTestCase::ReadEmpty()
{
static const char *confTest = "";
wxStringInputStream sis(confTest);
wxFileConfig fc(sis);
}
#endif // wxUSE_FILECONFIG #endif // wxUSE_FILECONFIG