From 8b3eb4a0699f201d864c0b151d0f57269cf6316f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 18 Nov 2010 12:41:13 +0000 Subject: [PATCH] Check wxDateTime components validity more rigorously. Check that the provided day is strictly positive and also that the month is in valid range: while it should always be, considering that it's an enum element, in practice people often cast ints to wxDateTime::Month with potentially fatal results. Catch this with an assert in wxDateTime::Tm::IsValid(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66203 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datetime.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 2a26b7b121..20b8e78240 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -519,9 +519,17 @@ wxDateTime::Tm::Tm(const struct tm& tm, const TimeZone& tz) bool wxDateTime::Tm::IsValid() const { + if ( mon == wxDateTime::Inv_Month ) + return false; + + // We need to check this here to avoid crashing in GetNumOfDaysInMonth() if + // somebody passed us "(wxDateTime::Month)1000". + wxCHECK_MSG( mon >= wxDateTime::Jan && mon < wxDateTime::Inv_Month, false, + wxS("Invalid month value") ); + // we allow for the leap seconds, although we don't use them (yet) return (year != wxDateTime::Inv_Year) && (mon != wxDateTime::Inv_Month) && - (mday <= GetNumOfDaysInMonth(year, mon)) && + (mday > 0 && mday <= GetNumOfDaysInMonth(year, mon)) && (hour < 24) && (min < 60) && (sec < 62) && (msec < 1000); } -- 2.45.2