]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote.c: reject 0-length branch names
authorGlen Choo <chooglen@google.com>
Tue, 31 May 2022 23:12:34 +0000 (23:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Jun 2022 17:49:51 +0000 (10:49 -0700)
Branch names can't be empty, so config keys with an empty branch name,
e.g. "branch..remote", are silently ignored.

Since these config keys will never be useful, make it a fatal error when
remote.c finds a key that starts with "branch." and has an empty
subsection.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c
t/t5516-fetch-push.sh

index ff04da1ec6295a8b4821c72803b433c0dba05cb3..98c190a0419ee2acec18aba0c55ea7c3191b24b1 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -352,8 +352,12 @@ static int handle_config(const char *key, const char *value, void *cb)
        struct remote_state *remote_state = cb;
 
        if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) {
+               /* There is no subsection. */
                if (!name)
                        return 0;
+               /* There is a subsection, but it is empty. */
+               if (!namelen)
+                       return -1;
                branch = make_branch(remote_state, name, namelen);
                if (!strcmp(subkey, "remote")) {
                        return git_config_string(&branch->remote_name, key, value);
index de0bab398e762245fd3799ca69e283e4928bfcaf..ff38563fb7cd7d2977e272f641b93f2c6cfd51f7 100755 (executable)
@@ -602,13 +602,23 @@ test_expect_success 'branch.*.pushremote config order is irrelevant' '
        check_push_result two_repo $the_commit heads/main
 '
 
-test_expect_success 'push ignores empty branch name entries' '
+test_expect_success 'push rejects empty branch name entries' '
        mk_test one_repo heads/main &&
        test_config remote.one.url one_repo &&
        test_config branch..remote one &&
        test_config branch..merge refs/heads/ &&
        test_config branch.main.remote one &&
        test_config branch.main.merge refs/heads/main &&
+       test_must_fail git push 2>err &&
+       grep "bad config variable .branch\.\." err
+'
+
+test_expect_success 'push ignores "branch." config without subsection' '
+       mk_test one_repo heads/main &&
+       test_config remote.one.url one_repo &&
+       test_config branch.autoSetupMerge true &&
+       test_config branch.main.remote one &&
+       test_config branch.main.merge refs/heads/main &&
        git push
 '