From: Thomas Bachem via GitGitGadget Date: Sat, 07 Nov 2026 08:42:34 GMT Subject: [PATCH 02/15] odb: handle NULL values for core.alternateRefs* config Message-ID: <74ab5bfc62c5f686450a6361d2bc6493b764a81e.1794040967.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 0200e26f21..ed59cfc989 100644 --- a/odb.c +++ b/odb.c @@ -379,7 +379,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); @@ -391,7 +391,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 2fb6d549d3..13abd81e98 100755 --- a/t/t5618-alternate-refs.sh +++ b/t/t5618-alternate-refs.sh @@ -58,4 +58,13 @@ test_expect_success 'log --source shows .alternate marker' ' 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