]> git.ipfire.org Git - thirdparty/git.git/commit
config: fix segfault when parsing "core.abbrev" without repo
authorPatrick Steinhardt <ps@pks.im>
Wed, 12 Jun 2024 08:03:23 +0000 (10:03 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Jun 2024 19:57:18 +0000 (12:57 -0700)
commit524c0183c999c59940ce1a8712b78e4dbd87ae60
treef3795af6ad2bd425b4bf83b3c2d5398afb93273a
parent9eaef5822cd76bbeb53b6479ce0ddaad34ee2b14
config: fix segfault when parsing "core.abbrev" without repo

The "core.abbrev" config allows the user to specify the minimum length
when abbreviating object hashes. Next to the values "auto" and "no",
this config also accepts a concrete length that needs to be bigger or
equal to the minimum length and smaller or equal to the hash algorithm's
hex length. While the former condition is trivial, the latter depends on
the object format used by the current repository. It is thus a variable
upper boundary that may either be 40 (SHA-1) or 64 (SHA-256).

This has two major downsides. First, the user that specifies this config
must be aware of the object hashes that its repository use. If they want
to configure the value globally, then they cannot pick any value in the
range `[41, 64]` if they have any repository that uses SHA-1. If they
did, Git would error out when parsing the config.

Second, and more importantly, parsing "core.abbrev" crashes when outside
of a Git repository because we dereference `the_hash_algo` to figure out
its hex length. Starting with c8aed5e8da (repository: stop setting SHA1
as the default object hash, 2024-05-07) though, we stopped initializing
`the_hash_algo` outside of Git repositories.

Fix both of these issues by not making it an error anymore when the
given length exceeds the hash length. Instead, leave the abbreviated
length intact. `repo_find_unique_abbrev_r()` handles this just fine
except for a performance penalty which we will fix in a subsequent
commit.

Reported-by: Kyle Lippincott <spectral@google.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
t/t4202-log.sh
t/t5601-clone.sh