[PATCH v2 02/15] odb: handle NULL values for core.alternateRefs* config
- From
Thomas Bachem via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 10, 2026, 07:36 UTC
- Message-ID
- <9170c4162f1902d99f480686f99e09fb82001879.1794296205.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2297.v2.git.1794296205.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
A core.alternateRefsCommand or core.alternateRefsPrefixes without a value makes "git fetch", "git receive-pack" and "git rev-list --alternate-refs" segfault in a repository that borrows objects from an alternate: fill_alternate_refs_command() passes the NULL value to strvec_push() or strvec_split().
Both settings take a string. Read them with repo_config_get_string_tmp(), which rejects a missing value with config_error_nonbool(), as the previous commit does for rebase.missingCommitsCheck.
Assisted-by: Claude Fable 5.1 Signed-off-by: Thomas Bachem <mail@thomasbachem.com> --- odb.c | 4 ++-- t/t5618-alternate-refs.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/odb.c b/odb.c index 865c404910..ea086be8b3 100644 --- a/odb.c +++ b/odb.c @@ -161,7 +161,7 @@ static void fill_alternate_refs_command(struct repository *repo, { const char *value; - if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) { + if (!repo_config_get_string_tmp(repo, "core.alternateRefsCommand", &value)) { cmd->use_shell = 1; strvec_push(&cmd->args, value); @@ -173,7 +173,7 @@ static void fill_alternate_refs_command(struct repository *repo, strvec_push(&cmd->args, "for-each-ref"); strvec_push(&cmd->args, "--format=%(objectname)"); - if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) { + if (!repo_config_get_string_tmp(repo, "core.alternateRefsPrefixes", &value)) { strvec_push(&cmd->args, "--"); strvec_split(&cmd->args, value); } diff --git a/t/t5618-alternate-refs.sh b/t/t5618-alternate-refs.sh index 68139a1b3e..422da6dde7 100755 --- a/t/t5618-alternate-refs.sh +++ b/t/t5618-alternate-refs.sh @@ -83,4 +83,13 @@ test_expect_success 'refs of a shallow alternate are ignored' ' test_cmp expect actual ' +test_expect_success 'alternateRefsCommand and alternateRefsPrefixes need a value' ' + test_must_fail git -c core.alternateRefsCommand \ + rev-list --alternate-refs 2>err && + test_grep "missing value for .core.alternateRefsCommand." err && + test_must_fail git -c core.alternateRefsPrefixes \ + rev-list --alternate-refs 2>err && + test_grep "missing value for .core.alternateRefsPrefixes." err +' + test_done
-- gitgitgadget