Skip to content

date: fix integer overflows in relative dates - #7459

Open
b84330808 wants to merge 1 commit into
libgit2:mainfrom
b84330808:date-relative-overflow
Open

b84330808 wants to merge 1 commit into
libgit2:mainfrom
b84330808:date-relative-overflow

Conversation

@b84330808

Copy link
Copy Markdown

"5000 fridays ago" computes 35000 days in seconds in an int. On LP64 the wrapped value goes through update_tm()'s unsigned long and the date comes out about 40 years in the future. "4294967297 days ago" is cut down to "1 day ago", and "6442450944 years ago" subtracts INT_MIN from tm_year. UBSan flags all of the overflows, and the revparse fuzzer can reach them through @{...}.

update_tm() now takes a git_time_t, and a number that doesn't fit an int is ignored, as is already done for one with too much zero-padding.

"5000 fridays ago" computes 35000 days in seconds in an int. That is undefined,
and on LP64 the wrapped value then went through update_tm()'s unsigned long
argument, so the date came out about 40 years in the future.

The same unsigned long is 32 bits on Windows, where "8000 weeks ago" wrapped
before reaching update_tm(). Take the seconds as a git_time_t and do the
arithmetic in it.

approxidate_digit() also stored an unsigned long in an int. "4294967297 days
ago" meant "1 day ago", and "6442450944 years ago" subtracted INT_MIN from
tm_year. Ignore a number that doesn't fit, as is already done for one with too
much zero-padding.

These parsers are reachable from the revparse fuzzer through "@{...}".

This branch has not been deployed

No deployments
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