From: Thomas Bachem via GitGitGadget Date: Tue, 10 Nov 2026 07:36:32 GMT Subject: [PATCH v2 02/15] odb: handle NULL values for core.alternateRefs* config Message-ID: <9170c4162f1902d99f480686f99e09fb82001879.1794296205.git.gitgitgadget@gmail.com> In-Reply-To: From: Thomas Bachem 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 --- 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