{"thread":{"id":"37996","subject":"[PATCH v3 0/1] Don't make $GIT_DIR/config executable","startedAt":"2014-11-18T13:50:23Z","lastAt":"2014-11-18T17:17:37Z","messageCount":3,"participants":["Michael Haggerty","Stefan Beller"],"isPatch":true,"patchVersion":3,"patchTotal":1},"messages":[{"id":"252082","messageId":"1416318624-23048-1-git-send-email-mhagger@alum.mit.edu","threadId":"37996","inReplyTo":null,"subject":"[PATCH v3 0/1] Don't make $GIT_DIR/config executable","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-18T13:50:23Z","receivedAt":"2014-11-18T13:50:23Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Here is a new, svelte version of the patch to avoid setting the u+x\nbit on $GIT_DIR/config. Thanks to the many people who reviewed\nversions v1 [1] and v2 [2].\n\nThis time there is no attempt to fix the permissions in existing\nrepositories; it only avoids creating new problems. It also includes a\ntest, as suggested by Eric and sketched by Junio.\n\nThis version, like the previous versions, applies to maint. But\n(thanks to its new minimalist nature) this version can be merged to\nmaster without conflict.\n\nMichael\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/259620\n[2] http://thread.gmane.org/gmane.comp.version-control.git/259644\n\nMichael Haggerty (1):\n  create_default_files(): don't set u+x bit on $GIT_DIR/config\n\n builtin/init-db.c | 3 ++-\n t/t0001-init.sh   | 7 +++++++\n 2 files changed, 9 insertions(+), 1 deletion(-)\n\n-- \n2.1.3\n"},{"id":"252083","messageId":"1416318624-23048-2-git-send-email-mhagger@alum.mit.edu","threadId":"37996","inReplyTo":"1416318624-23048-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 1/1] create_default_files(): don't set u+x bit on $GIT_DIR/config","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-18T13:50:24Z","receivedAt":"2014-11-18T13:50:24Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Since time immemorial, the test of whether to set \"core.filemode\" has\nbeen done by trying to toggle the u+x bit on $GIT_DIR/config and then\ntesting whether the change \"took\". I find it somewhat odd to use the\nconfig file for this test, but whatever.\n\nThe test code didn't set the u+x bit back to its original state\nitself, instead relying on the subsequent call to git_config_set() to\nre-write the config file with correct permissions.\n\nBut ever since\n\n    daa22c6f8d config: preserve config file permissions on edits (2014-05-06)\n\ngit_config_set() copies the permissions from the old config file to\nthe new one. This is a good change in and of itself, but it interacts\nbadly with create_default_files()'s sloppiness, causing \"git init\" to\nleave the executable bit set on $GIT_DIR/config.\n\nSo change create_default_files() to reset the permissions on\n$GIT_DIR/config after its test.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n builtin/init-db.c | 3 ++-\n t/t0001-init.sh   | 7 +++++++\n 2 files changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 56f85e2..a6d58fd 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -254,7 +254,8 @@ static int create_default_files(const char *template_path)\n \t\tstruct stat st2;\n \t\tfilemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&\n \t\t\t\t!lstat(path, &st2) &&\n-\t\t\t\tst1.st_mode != st2.st_mode);\n+\t\t\t\tst1.st_mode != st2.st_mode &&\n+\t\t\t\t!chmod(path, st1.st_mode));\n \t}\n \tgit_config_set(\"core.filemode\", filemode ? \"true\" : \"false\");\n \ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex e62c0ff..7de8d85 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -12,6 +12,13 @@ check_config () {\n \t\techo \"expected a directory $1, a file $1/config and $1/refs\"\n \t\treturn 1\n \tfi\n+\n+\tif test_have_prereq POSIXPERM && test -x \"$1/config\"\n+\tthen\n+\t\techo \"$1/config is executable?\"\n+\t\treturn 1\n+\tfi\n+\n \tbare=$(cd \"$1\" && git config --bool core.bare)\n \tworktree=$(cd \"$1\" && git config core.worktree) ||\n \tworktree=unset\n-- \n2.1.3\n"},{"id":"252089","messageId":"CAGZ79kbTu5OGkJc4LUxKZ_4T4YpQwFB3+5b2iz8_f=r6VJ6faA@mail.gmail.com","threadId":"37996","inReplyTo":"1416318624-23048-2-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH v3 1/1] create_default_files(): don't set u+x bit on $GIT_DIR/config","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2014-11-18T17:17:37Z","receivedAt":"2014-11-18T17:17:37Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Reviewed-by: Stefan Beller <sbeller@google.com>\n\nOn Tue, Nov 18, 2014 at 5:50 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:\n> Since time immemorial, the test of whether to set \"core.filemode\" has\n> been done by trying to toggle the u+x bit on $GIT_DIR/config and then\n> testing whether the change \"took\". I find it somewhat odd to use the\n> config file for this test, but whatever.\n>\n> The test code didn't set the u+x bit back to its original state\n> itself, instead relying on the subsequent call to git_config_set() to\n> re-write the config file with correct permissions.\n>\n> But ever since\n>\n>     daa22c6f8d config: preserve config file permissions on edits (2014-05-06)\n>\n> git_config_set() copies the permissions from the old config file to\n> the new one. This is a good change in and of itself, but it interacts\n> badly with create_default_files()'s sloppiness, causing \"git init\" to\n> leave the executable bit set on $GIT_DIR/config.\n>\n> So change create_default_files() to reset the permissions on\n> $GIT_DIR/config after its test.\n>\n> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n> ---\n>  builtin/init-db.c | 3 ++-\n>  t/t0001-init.sh   | 7 +++++++\n>  2 files changed, 9 insertions(+), 1 deletion(-)\n>\n> diff --git a/builtin/init-db.c b/builtin/init-db.c\n> index 56f85e2..a6d58fd 100644\n> --- a/builtin/init-db.c\n> +++ b/builtin/init-db.c\n> @@ -254,7 +254,8 @@ static int create_default_files(const char *template_path)\n>                 struct stat st2;\n>                 filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&\n>                                 !lstat(path, &st2) &&\n> -                               st1.st_mode != st2.st_mode);\n> +                               st1.st_mode != st2.st_mode &&\n> +                               !chmod(path, st1.st_mode));\n>         }\n>         git_config_set(\"core.filemode\", filemode ? \"true\" : \"false\");\n>\n> diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> index e62c0ff..7de8d85 100755\n> --- a/t/t0001-init.sh\n> +++ b/t/t0001-init.sh\n> @@ -12,6 +12,13 @@ check_config () {\n>                 echo \"expected a directory $1, a file $1/config and $1/refs\"\n>                 return 1\n>         fi\n> +\n> +       if test_have_prereq POSIXPERM && test -x \"$1/config\"\n> +       then\n> +               echo \"$1/config is executable?\"\n> +               return 1\n> +       fi\n> +\n>         bare=$(cd \"$1\" && git config --bool core.bare)\n>         worktree=$(cd \"$1\" && git config core.worktree) ||\n>         worktree=unset\n> --\n> 2.1.3\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"}]}