]> git.saurik.com Git - wxWidgets.git/commitdiff
Check for end of string when parsing "%z" in wxDateTime::Format().
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 9 Mar 2012 01:09:20 +0000 (01:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 9 Mar 2012 01:09:20 +0000 (01:09 +0000)
We could dereference an invalid iterator when parsing "%z", check for this in
the code and add a unit test for this case.

Closes #14075.

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

src/common/datetimefmt.cpp
tests/datetime/datetimetest.cpp

index fed909fe8a3fb05763c16a03f75bd1ebd21953a6..c75d2e2c18fde81fecb8ae6b84cd469178207eb1 100644 (file)
@@ -1408,6 +1408,11 @@ wxDateTime::ParseFormat(const wxString& date,
 
             case wxT('z'):
                 {
+                    // check that we have something here at all
+                    if ( input == end )
+                        return false;
+
+                    // and then check that it's either plus or minus sign
                     bool minusFound;
                     if ( *input == wxT('-') )
                         minusFound = true;
index 3d4fad74d1683229391dd9ff610a7151e3f7e4e5..71821d92e88f3449b3b1642d8c53890390cf2ae4 100644 (file)
@@ -829,6 +829,9 @@ void DateTimeTestCase::TestTimeFormat()
     CPPUNIT_ASSERT( dt.ParseFormat("17", "%d") );
     CPPUNIT_ASSERT_EQUAL( 17, dt.GetDay() );
 
+    // test some degenerate cases
+    CPPUNIT_ASSERT( !dt.ParseFormat("", "%z") );
+
     // test compilation of some calls which should compile (and not result in
     // ambiguity because of char*<->wxCStrData<->wxString conversions)
     wxString s("foo");