]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: fix safe.directory key not being checked
authorMatheus Valadares <me@m28.io>
Wed, 13 Apr 2022 15:32:30 +0000 (15:32 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 Apr 2022 19:42:51 +0000 (12:42 -0700)
It seems that nothing is ever checking to make sure the safe directories
in the configs actually have the key safe.directory, so some unrelated
config that has a value with a certain directory would also make it a
safe directory.

Signed-off-by: Matheus Valadares <me@m28.io>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c
t/t0033-safe-directory.sh

diff --git a/setup.c b/setup.c
index 3c6ed17af9566a7097067facbcfbda967ef421aa..4b9f073617c2c67db178ee3d8cc8d0755cd97c1f 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1034,6 +1034,9 @@ static int safe_directory_cb(const char *key, const char *value, void *d)
 {
        struct safe_directory_data *data = d;
 
+       if (strcmp(key, "safe.directory"))
+               return 0;
+
        if (!value || !*value)
                data->is_safe = 0;
        else {
index 9380ff3d01709602258a425596e734d08eea64fd..6f33c0dfefaaf30264c903274dd60c7243d92418 100755 (executable)
@@ -21,6 +21,11 @@ test_expect_success 'safe.directory does not match' '
        expect_rejected_dir
 '
 
+test_expect_success 'path exist as different key' '
+       git config --global foo.bar "$(pwd)" &&
+       expect_rejected_dir
+'
+
 test_expect_success 'safe.directory matches' '
        git config --global --add safe.directory "$(pwd)" &&
        git status