Skip to content

fix datetime: size TimestampToString buffer for years past 9999 - #1328

Open
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:datetime-timestamp-buffer-size
Open

fix datetime: size TimestampToString buffer for years past 9999#1328
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:datetime-timestamp-buffer-size

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor
  1. TimestampToString formats a time_t with strftime("%Y-%m-%dT%H:%M:%S+0000") into a fixed 25-byte buffer and always returns the first 24 bytes, guarded only by UASSERT(ret == 24) which is compiled out under NDEBUG.
  2. For a timestamp in year 10000 or later the %Y field is 5 or more digits, so the output does not fit: strftime returns 0 and leaves the buffer contents unspecified, yet the function still returns 24 bytes of it. That is an uninitialized-stack read in release builds (and the assertion aborts in debug builds).
  3. Sized the buffer for any 64-bit year, value-initialized it, and return the exact number of bytes strftime wrote. Output for years up to 9999 is unchanged; added a regression in datetime_test.cpp for a year-10000 timestamp.

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