Skip to content

Commit

Permalink
Fix ASSERT_SAFE from bad BER date. (#4732)
Browse files Browse the repository at this point in the history
  • Loading branch information
cppguru authored and GitHub Enterprise committed May 9, 2024
1 parent e5ec57f commit 53725e3
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 187 deletions.
10 changes: 10 additions & 0 deletions groups/bal/balber/balber_berutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,11 @@ int BerUtil_DatetimeImpUtil::getExtendedBinaryDatetimeValue(
bdlt::ProlepticDateImpUtil::serialToYmd(
&year, &month, &day, daysSince0001Jan01);

// Make sure that the date actually exists before trying to create it
if (!bdlt::SerialDateImpUtil::isValidYearMonthDay(year, month, day)) {
return -1; // RETURN
}

const bdlt::Date date(year, month, day);

bsls::Types::Int64 microsecondsSinceMidnight;
Expand Down Expand Up @@ -2202,6 +2207,11 @@ int BerUtil_DatetimeImpUtil::getExtendedBinaryDatetimeTzValue(
bdlt::ProlepticDateImpUtil::serialToYmd(
&year, &month, &day, daysSince0001Jan01);

// Make sure that Date think it's actually valid before trying to create it
if (!bdlt::SerialDateImpUtil::isValidYearMonthDay(year, month, day)) {
return -1; // RETURN
}

const bdlt::Date date(year, month, day);

bsls::Types::Int64 microsecondsSinceMidnight;
Expand Down
Loading

0 comments on commit 53725e3

Please sign in to comment.