]> git.ipfire.org Git - thirdparty/git.git/commit
ref-filter: don't look for objects when outside of a repository
authorSZEDER Gábor <szeder.dev@gmail.com>
Wed, 14 Nov 2018 12:27:25 +0000 (13:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Nov 2018 04:49:08 +0000 (13:49 +0900)
commit47bd3d0c14f081a3ea32b0720f7d59559802904d
tree35bdf1d3e87d0b7fa61aafa3e6b60e4682233371
parentd166e6afe5f257217836ef24a73764eba390c58d
ref-filter: don't look for objects when outside of a repository

The command 'git ls-remote --sort=authordate <remote>' segfaults when
run outside of a repository, ever since the introduction of its
'--sort' option in 1fb20dfd8e (ls-remote: create '--sort' option,
2018-04-09).

While in general the 'git ls-remote' command can be run outside of a
repository just fine, its '--sort=<key>' option with certain keys does
require access to the referenced objects.  This sorting is implemented
using the generic ref-filter sorting facility, which already handles
missing objects gracefully with the appropriate 'missing object
deadbeef for HEAD' message.  However, being generic means that it
checks replace refs while trying to retrieve an object, and while
doing so it accesses the 'git_replace_ref_base' variable, which has
not been initialized and is still a NULL pointer when outside of a
repository, thus causing the segfault.

Make ref-filter more careful upfront while parsing the format string,
and make it error out when encountering a format atom requiring object
access when we are not in a repository.  Also add a test to ensure
that 'git ls-remote --sort' fails gracefully when executed outside of
a repository.

Reported-by: H.Merijn Brand <h.m.brand@xs4all.nl>
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ref-filter.c
t/t5512-ls-remote.sh