Skip to content

fix grpc: reject out-of-range day in datetime IsValid - #1320

Open
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:grpc-date-isvalid-day-narrowing
Open

fix grpc: reject out-of-range day in datetime IsValid#1320
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:grpc-date-isvalid-day-narrowing

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor
  1. IsValid(google::type::Date) reads the wire-controlled day() as an int32 but compares std::chrono::day(day()) against DaysInMonth, and std::chrono::day holds its value in an unsigned char, so day() is taken modulo 256 before the upper-bound check while the day() >= 1 guard still sees the full int.
  2. Out-of-range days that reduce to a legal value pass validation: 286 becomes 30, 271 becomes 15, 256 becomes 0, so IsValid returns true for each.
  3. ToUtilsDate, ToYearMonthDay and ToTimePoint use IsValid as their only gate before converting a peer-supplied Date, so an out-of-range day is accepted and later silently reinterpreted as a different day.

Compared the raw day() against DaysInMonth as an int so the untrusted value is no longer narrowed before the check.
Added DatetimeUtilsDateIsValid cases for day 256 and 286, which return true on the current code and false after the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant