Re: [PATCH 4/5] log: handle integer overflow in timestamps
- From
Jeff King <peff@peff.net>
- Date
- Feb 24, 2014, 19:58 UTC
- Message-ID
- <20140224195829.GA11940@sigill.intra.peff.net>
- In-Reply-To
- <xmqqsir88f4n.fsf@gitster.dls.corp.google.com>
On Mon, Feb 24, 2014 at 11:50:00AM -0800, Junio C Hamano wrote:
Show 18 quoted lines
> > We also recognize overflow in the timezone field, which
> > could produce nonsensical results. In this case we show the
> > parsed date, but in UTC.
>
> Both are good measures to fallback to sanity, but why is that
> if/else? In other words...
>
> > + if (date_overflows(date))
> > + date = 0;
> > + else {
> > + if (ident->tz_begin && ident->tz_end)
> > + tz = strtol(ident->tz_begin, NULL, 10);
> > + if (tz == LONG_MAX || tz == LONG_MIN)
> > + tz = 0;
> > + }
>
> ... don't we want to fix an input having a bogus timestamp and also
> a bogus tz recorded in it?If there is a bogus timestamp, then we do not want to look at tz at all. We leave it at "0", so that we get a true sentinel:
Thu Jan 1 00:00:00 1970 +0000
and not:
Wed Dec 31 19:00:00 1969 -0500
If the timestamp is valid, then we bother to parse the zone, and handle overflow there.
-Peff