]> git.ipfire.org Git - thirdparty/git.git/commit
refs/ref-cache: fix SEGFAULT when seeking in empty directories
authorKarthik Nayak <karthik.188@gmail.com>
Wed, 1 Oct 2025 12:17:29 +0000 (14:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2025 20:12:24 +0000 (13:12 -0700)
commit351c6e719ae9c5b97506dde6bc287408b80e87e4
tree23f1bf0ea4c1356fd8279e8e39bcdfff50f2ff5f
parent821f583da6d30a84249f75f33501504d597bc16b
refs/ref-cache: fix SEGFAULT when seeking in empty directories

The 'cache_ref_iterator_seek()' function is used to seek the
`ref_iterator` to the desired reference in the ref-cache mechanism. We
use the seeking functionality to implement the '--start-after' flag in
'git-for-each-ref(1)'.

When using the files-backend with packed-refs, it is possible that some
of the refs directories are empty. For e.g. just after repacking, the
'refs/heads' directory would be empty. The ref-cache seek mechanism,
doesn't take this into consideration when descending into a
subdirectory, and makes an out of bounds access, causing SEGFAULT as we
try to access entries within the directory. Fix this by breaking out of
the loop when we enter an empty directory.

Since we start with the base directory of 'refs/' which is never empty,
it is okay to perform this check after the first iteration in the
`do..while` clause.

Add tests which simulate this behavior and also provide coverage over
using the feature over packed-refs.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/ref-cache.c
t/t6302-for-each-ref-filter.sh