Re: Timestamp of zero in reflog considered invalid
- From
Andreas Schwab <schwab@linux-m68k.org>
- Date
- Apr 5, 2016, 17:41 UTC
- Message-ID
- <87r3ek3qc9.fsf@linux-m68k.org>
- In-Reply-To
- <xmqqbn5o2gv1.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 18 quoted lines
> Checking the value against ULONG_MAX and errno==ERANGE would be an > improvement. It may be debatable if we should silently ignore an > entry with an invalid timestamp, but that is a separate issue. > > refs.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/refs.c b/refs.c > index 4e15f60..ff24184 100644 > --- a/refs.c > +++ b/refs.c > @@ -3701,7 +3701,8 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c > get_sha1_hex(sb->buf + 41, nsha1) || sb->buf[81] != ' ' || > !(email_end = strchr(sb->buf + 82, '>')) || > email_end[1] != ' ' || > - !(timestamp = strtoul(email_end + 2, &message, 10)) || > + ((timestamp = strtoul(email_end + 2, &message, 10)) == ULONG_MAX && > + errno == ERANGE) ||
You need to set errno = 0 before calling strtoul, to distinguish the valid return of ULONG_MAX (which would keep errno intact) and a real overflow.
Andreas.
-- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."