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

Re: [PATCH] trailers: stop recognizing URLs as trailers

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 2, 2026, 22:36 UTC
Message-ID
<xmqqmrv42lrg.fsf@gitster.g>
In-Reply-To
<URLs_not_trailers.b13@msgid.xyz>
kristofferhaugsbakk@fastmail.com writes:
Show 10 quoted lines
> From: Kristoffer Haugsbakk <code@khaugsbakk.name>
>
> An HTTPS URL starts with an alphanumeric scheme followed by a colon.
> That means that they will be recognized as trailers in a trailer block.
> That turns out to be a problem in practice. Let’s stop recognizing these
> as trailers by failing the trailer parsing when we:
>
> 1. find the separator;
> 2. the separator and the next two characters form `://`; and
> 3. we haven’t parsed any whitespace yet.

When I read the problem description, I would have expected you to say "If we find <token>: at the beginning of the line, check <token> against known URL schemes like https, ftp, etc. and declare that the line is not a trailer, if it matches". Checking against "://" is much more robust, as it is less likely to happen in random text, and we avoid maintaining a whitelist of scheme names. You are certainly smarter than I am ;-).

Shouldn't we restrict the token preceding "://" more strictly than simply prohibiting whitespace?

> Helped-by: Jeff King <peff@peff.net>
> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
Show 12 quoted lines
> diff --git a/trailer.c b/trailer.c
> index 6d8ec7fa8d8..971ae459596 100644
> --- a/trailer.c
> +++ b/trailer.c
> @@ -635,8 +635,13 @@ static ssize_t find_separator(const char *line, const char *separators)
>  	int whitespace_found = 0;
>  	const char *c;
>  	for (c = line; *c; c++) {
> -		if (strchr(separators, *c))
> +		if (strchr(separators, *c)) {
> +			/* avoid accidental URL matches (://) */
> +			if (*c == ':' && c[1] == '/' && c[2] == '/' &&

How do we know the references to c[1] and c[2] do not access an unmapped piece of memory? The answer is that line[] is NUL terminated, so c[0] == ':' guarantees that c[1] is safe to read and unless it is NUL (and c[1] =='/' certainly means it is not NUL), c[2] is safe to read.

OK.  Makes sense to me.
Thanks.
Show 7 quoted lines
> +			    !whitespace_found)
> +				return -1;
>  			return c - line;
> +		}
>  		if (!whitespace_found && (isalnum(*c) || *c == '-'))
>  			continue;
>  		if (c != line && (*c == ' ' || *c == '\t')) {
Previous: kristofferhaugsbakk@fastmail.comNext: Kristoffer Haugsbakk
Message 7 of 18 in “trailers: --only-trailers normalizes URLs to trailers”
  1. Kristoffer HaugsbakkJun 4, 2026
  2. Jeff KingJun 9, 2026
  3. Kristoffer HaugsbakkJun 10, 2026
  4. Jeff KingJun 11, 2026
  5. Kristoffer HaugsbakkJun 11, 2026
  6. trailers: stop recognizing URLs as trailerskristofferhaugsbakk@fastmail.com, Aug 2, 2026
  7. Junio C HamanoAug 2, 2026
  8. Kristoffer HaugsbakkAug 3, 2026
  9. Jeff KingAug 3, 2026
  10. Junio C HamanoAug 3, 2026
  11. Kristoffer HaugsbakkAug 6, 2026
  12. Junio C HamanoAug 20, 2026
  13. Kristoffer HaugsbakkAug 20, 2026
  14. Jeff KingAug 21, 2026
  15. trailers: stop recognizing URLs as trailerskristofferhaugsbakk@fastmail.com, Aug 20, 2026
  16. trailers: stop recognizing URLs as trailerskristofferhaugsbakk@fastmail.com, Aug 21, 2026
  17. Kristoffer HaugsbakkAug 21, 2026
  18. Junio C HamanoAug 21, 2026

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.