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

Re: input validation in receive-pack

From
MKMartin Koegler <mkoegler@auto.tuwien.ac.at>
Date
Jan 2, 2008, 07:51 UTC
Message-ID
<20080102075152.GA24401@auto.tuwien.ac.at>
In-Reply-To
<7vzlvp3oya.fsf@gitster.siamese.dyndns.org>
On Tue, Jan 01, 2008 at 07:07:25PM -0800, Junio C Hamano wrote:
Show 16 quoted lines
> mkoegler@auto.tuwien.ac.at (Martin Koegler) writes:
> > Some lines above:
> > |        if (!prefixcmp(name, "refs/") && check_ref_format(name + 5)) {
> > |                error("refusing to create funny ref '%s' remotely", name);
> > |                return "funny refname";
> > |        }
> >
> > Is this code really correct?
> 
> Interesting.  Things have been this way forever, I think.  I do
> not offhand see any reason not to refuse refs outside refs/, so
> you can try 
> 
> 	if (prefixcmp(name, "refs/") || check_ref_format(name +	5))
> 
> and see what happens. 
I tried this and it passed the test suite.
>  Some people may however want to push to
> HEAD (that is ".git/HEAD" which is outside ".git/refs"), though.
If pushing to HEAD is allowed, it bypasses the fast-forward check.

As minimum, if (check_ref_format(name)) should be safer, as it rejects totally invalid refnames (especially ../[...]).

Are there more refs outside "refs/", which somebody would want to push to? If not, the following patch could work:

if (!strcmp(name, "HEAD") && 
   (prefixcmp(name, "refs/") || check_ref_format(name+5))) {
  [..error..]
}
if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
    !is_null_sha1(old_sha1) &&
    (!prefixcmp(name, "refs/heads/")||!strcmp(name, "HEAD")) {
[...]
}
mfg Martin Kögler
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 8 in “input validation in receive-pack”
  1. Martin KoeglerJan 1, 2008
  2. Junio C HamanoJan 2, 2008
  3. Daniel BarkalowJan 2, 2008
  4. Junio C HamanoJan 2, 2008
  5. Daniel BarkalowJan 2, 2008
  6. Junio C HamanoJan 2, 2008
  7. Martin KoeglerJan 2, 2008
  8. Junio C HamanoJan 2, 2008

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.