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
This commit is contained in:
Vadim Zeitlin 2010-11-18 12:41:13 +00:00
parent ca96978a98
commit 8b3eb4a069

View File

@ -519,9 +519,17 @@ wxDateTime::Tm::Tm(const struct tm& tm, const TimeZone& tz)
bool wxDateTime::Tm::IsValid() const 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) // we allow for the leap seconds, although we don't use them (yet)
return (year != wxDateTime::Inv_Year) && (mon != wxDateTime::Inv_Month) && 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); (hour < 24) && (min < 60) && (sec < 62) && (msec < 1000);
} }