Re: gitweb bug report: hash mistaken for an option
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 18, 2026, 21:47 UTC
- Message-ID
- <xmqqikasq06q.fsf@gitster.g>
- In-Reply-To
- <absJmT_S9gGqbwyT@phare.normalesup.org>
Nicolas George <george@nsup.org> writes:
Show 22 quoted lines
> Hi. > > We have a web server with gitweb (from Debian), and we observed git error > messages in apache's error.log. I tracked down the issue to a request that > had this: > > ``` > ?p=…/.git;a=tree;hb=-c > ``` > > I will not bother giving the actual URL since nobody else can check the > issue in the logs or our server, but the issue can be reproduced on any > server by replacing the `hb=…` parameter with `hb=-c`. > > I tracked down the issue further to the `git_tree` function of the CGI > script: > > <https://git.kernel.org/pub/scm/git/git.git/tree/gitweb/gitweb.perl#n7200> > > If `$hash_base`, i.e. the `hb` parameter, is set and not `$file_name`, then > it is passed as is as the last argument of `ls-tree -z`, and since it is not > a valid hash, it prints an error.
In other words, garbage-in garbage-out?
FWIW, this also gives an error message
$ git ls-tree no-such-tree
fatal: Not a valid object name no-suchand even though it may give slightly a smaller error message than "git ls-tree -c", it would not stay silent. So I am not sure if there is anything to fix here, short of redirecting your standard error to /dev/null or something.
Show 5 quoted lines
> Second, that the error (be it “unknown switch”, “Not a valid object name” or > “not a tree object” gets written into the error log: it is an error entirely > caused by the client that has no repercussion on the server, it should be > either passed back to the client or ignored. This is more minor but harder > to fix.
For that, you'd need to capture standard error stream and relay it to the user, I guess. That does sound like the right fix to deal with any wrong input that comes in the web request.
This is a tangent, but I actually think "ls-tree -- $whatever" that forces $whatever to be interpreted as the tree object name _is_ a bug. A double-dash should signal end of revisions and beginning of the pathspec. We may want to fix it in "git ls-tree", regardless of any gitweb issue.
While I do not think it is a fix to force the end-user supplied parameter to be interpreted as a tree object name, if we wanted to do so in durable way that won't be broken even after we correct the double-dash bug in ls-tree, we probably should write
$ git ls-tree -z --end-of-options $hb
instead.
Thanks.