git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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."
Previous: Junio C HamanoNext: Johannes Schindelin
Message 3 of 5 in “Timestamp of zero in reflog considered invalid”
  1. Erik BrayApr 5, 2016
  2. Junio C HamanoApr 5, 2016
  3. Andreas SchwabApr 5, 2016
  4. Johannes SchindelinApr 6, 2016
  5. Erik BrayApr 6, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.