From e4f54cce1e44bb64cb08db5823e08236ae2c87b4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 16 Nov 2010 22:37:52 +0000 Subject: [PATCH] Fix crashes in wxDateTime::ParseDate() for some invalid dates. Parsing an incomplete date with nothing but whitespace and/or date delimiter characters at the end crashed as we happily went beyond the end of string. Fix this by not using a loop which didn't check for the iterator validity. Closes #12685. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66166 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datetimefmt.cpp | 3 ++- tests/datetime/datetimetest.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index 64bb825190..a073b3fcfc 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -1625,9 +1625,10 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end) while ( p != pEnd ) { // skip white space and date delimiters - while ( wxStrchr(".,/-\t\r\n ", *p) ) + if ( wxStrchr(".,/-\t\r\n ", *p) ) { ++p; + continue; } // modify copy of the iterator as we're not sure if the next token is diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 90ec18c939..e21021e47a 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -973,6 +973,7 @@ void DateTimeTestCase::TestDateParse() { "29 Feb 2006" }, { "31/04/06" }, { "bloordyblop" }, + { "2 . . " }, }; // special cases