[PATCH 13/15] config: handle NULL value for remote URLs in hasconfig includes
- From
Thomas Bachem via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 7, 2026, 08:42 UTC
- Message-ID
- <5c12b13d90c40fdd933bcb868db4b593f47b99a6.1794040968.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2297.git.1794040967.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
When the configuration has an includeIf "hasconfig:remote.*.url:..." section, a remote.<name>.url without a value makes nearly every git command segfault, "git log" too: add_remote_url() passes the NULL value to string_list_append(), which copies it with xstrdup().
Leave such a URL out of the list that hasconfig:remote.*.url patterns are matched against. It cannot match a pattern, and wherever git reads its remotes, handle_config() in remote.c already rejects it with the usual error. Commands that never look at remotes keep working.
Assisted-by: Claude Opus 5.5 Signed-off-by: Thomas Bachem <mail@thomasbachem.com> --- config.c | 3 ++- t/t1300-config.sh | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/config.c b/config.c index e0bb29b53d..f6ccfd52dd 100644 --- a/config.c +++ b/config.c @@ -327,7 +327,8 @@ static int add_remote_url(const char *var, const char *value, if (!parse_config_key(var, "remote", &remote_name, &remote_name_len, &key) && remote_name && - !strcmp(key, "url")) + !strcmp(key, "url") && + value) string_list_append(remote_urls, value); return 0; } diff --git a/t/t1300-config.sh b/t/t1300-config.sh index e3f8064889..8fb920b1ba 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2970,6 +2970,28 @@ test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such test_grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err ' +test_expect_success 'includeIf.hasconfig:remote.*.url skips a url without a value' ' + git init hasremoteurlTest && + test_when_finished "rm -rf hasremoteurlTest" && + + cat >include-this <<-\EOF && + [user] + this = this-is-included + EOF + cat >>hasremoteurlTest/.git/config <<-EOF && + [remote "valueless"] + url + [remote "foo"] + url = foourl + [includeIf "hasconfig:remote.*.url:foourl"] + path = "$(pwd)/include-this" + EOF + + echo this-is-included >expect-this && + git -C hasremoteurlTest config --get user.this >actual-this && + test_cmp expect-this actual-this +' + test_expect_success 'negated mode causes failure' ' test_must_fail git config --no-get 2>err && test_grep "unknown option \`no-get${SQ}" err
-- gitgitgadget