[PATCH v2 10/15] setup: handle NULL value for safe.bareRepository
- From
Thomas Bachem via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 10, 2026, 07:36 UTC
- Message-ID
- <a5b6436943d4d0c9fdf4015106dd1bb89d006979.1794296205.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2297.v2.git.1794296205.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
A safe.bareRepository without a value makes git segfault in every bare repository it discovers, as in "git -C repo.git log": allowed_bare_repo_cb() passes the NULL value to strcmp().
Reject a missing value with config_error_nonbool(). The callback already fails for any value other than "explicit" and "all".
Assisted-by: Claude Opus 5.5 Signed-off-by: Thomas Bachem <mail@thomasbachem.com> --- setup.c | 2 ++ t/t0035-safe-bare-repository.sh | 6 ++++++ 2 files changed, 8 insertions(+)
diff --git a/setup.c b/setup.c index 186815c780..e9a1bdbb50 100644 --- a/setup.c +++ b/setup.c @@ -1531,6 +1531,8 @@ static int allowed_bare_repo_cb(const char *key, const char *value, if (strcasecmp(key, "safe.bareRepository")) return 0; + if (!value) + return config_error_nonbool(key); if (!strcmp(value, "explicit")) { *allowed_bare_repo = ALLOWED_BARE_REPO_EXPLICIT; return 0; diff --git a/t/t0035-safe-bare-repository.sh b/t/t0035-safe-bare-repository.sh index 1d3d19f5b4..a0e0c48d7d 100755 --- a/t/t0035-safe-bare-repository.sh +++ b/t/t0035-safe-bare-repository.sh @@ -80,6 +80,12 @@ test_expect_success 'safe.bareRepository on the command line' ' -c safe.bareRepository=all ' +test_expect_success 'safe.bareRepository without a value is rejected' ' + test_must_fail git -C outer-repo/bare-repo -c safe.bareRepository \ + rev-parse --git-dir 2>err && + test_grep "missing value for .safe.barerepository." err +' + test_expect_success 'safe.bareRepository in included file' ' cat >gitconfig-include <<-\EOF && [safe]
-- gitgitgadget