[PATCH 12/15] scalar: handle NULL value for scalar.repo
- From
Thomas Bachem via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 7, 2026, 08:42 UTC
- Message-ID
- <b4bcaf19ecbf0fc0e165f098c00dccf42985fdd9.1794040968.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2297.git.1794040967.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
A scalar.repo without a value makes "scalar reconfigure --all" segfault: get_scalar_repos() passes the NULL value to string_list_append(), which copies it with xstrdup().
Reject a missing value with config_error_nonbool(). This cannot break a working setup, as "scalar register" always writes scalar.repo with a path.
Assisted-by: Claude Opus 5.5 Signed-off-by: Thomas Bachem <mail@thomasbachem.com> --- scalar.c | 5 ++++- t/t9210-scalar.sh | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/scalar.c b/scalar.c index a80d8ee3ff..4fe4b2a647 100644 --- a/scalar.c +++ b/scalar.c @@ -652,8 +652,11 @@ static int get_scalar_repos(const char *key, const char *value, { struct string_list *list = data; - if (!strcmp(key, "scalar.repo")) + if (!strcmp(key, "scalar.repo")) { + if (!value) + return config_error_nonbool(key); string_list_append(list, value); + } return 0; } diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index c8463d0ac4..137765d3b8 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -288,6 +288,11 @@ test_expect_success '`reconfigure -a` removes stale config entries' ' test_cmp expect scalar.repos ' +test_expect_success '`reconfigure -a` rejects scalar.repo without a value' ' + test_must_fail scalar -c scalar.repo reconfigure -a 2>err && + test_grep "missing value for .scalar.repo." err +' + test_expect_success 'scalar delete without enlistment shows a usage' ' test_expect_code 129 scalar delete '
-- gitgitgadget