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

Re: [PATCH] symbolic-ref: check format of given reference

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 18, 2012, 17:10 UTC
Message-ID
<7vipeo4kcp.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vr4tc4lsc.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 11 quoted lines
> From: Michael Schubert <mschub@elegosoft.com>
> Date: Sun, 17 Jun 2012 22:26:37 +0200
> Subject: [PATCH] symbolic-ref: check format of given reference
>
> Currently, it's possible to update HEAD with a nonsense reference since
> no strict validation is performed. Example:
>
> 	$ git symbolic-ref HEAD 'refs/heads/master
>     >
>     >
>     > '

It would be nice to add a new test or two to t1401. 1401.3 was already trying to catch a malformed reference with this test:

	test_must_fail git symbolic-ref HEAD foo

and it did trigger thanks to the prefixcmp(argv[1], "refs/") test we already have. Probably something like

	git symbolic-ref HEAD "refs/heads/.foo"
	git symbolic-ref HEAD "refs/heads/-foo"
would be a good start.

To make the latter _correctly_ work requires a bit of work, though. We should make sure all the check_refname_format() callers pass the full path to a ref, get rid of ALLOW_ONELEVEL, and redo commits like 6348624 (disallow branch names that start with a hyphen, 2010-09-14) and 4f0accd (tag: disallow '-' as tag name, 2011-05-10).

For that matter, shouldn't symbolic-ref be forbidden to point outside refs/heads/, not just restricted in refs/ like the current code does?

Previous: Junio C HamanoNext: Jeff King
Message 5 of 8 in “symbolic-ref: check format of given reference”
  1. symbolic-ref: check format of given referenceMichael Schubert, Jun 17, 2012
  2. Junio C HamanoJun 17, 2012
  3. Michael SchubertJun 18, 2012
  4. Junio C HamanoJun 18, 2012
  5. Junio C HamanoJun 18, 2012
  6. Jeff KingJun 19, 2012
  7. Jeff KingJun 19, 2012
  8. Michael SchubertJun 19, 2012

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.