From: Thomas Bachem via GitGitGadget Date: Tue, 10 Nov 2026 07:36:43 GMT Subject: [PATCH v2 13/15] config: handle NULL value for remote URLs in hasconfig includes Message-ID: <080106d5ea21d3e520dd28772435dcb32918c0a3.1794296205.git.gitgitgadget@gmail.com> In-Reply-To: From: Thomas Bachem When the configuration has an includeIf "hasconfig:remote.*.url:..." section, a remote..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 --- config.c | 3 ++- t/t1300-config.sh | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 5976a418d5..5b823b3dcd 100644 --- a/config.c +++ b/config.c @@ -342,7 +342,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