git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Yaroslav Halchenko" <yoh@onerussian.com>,
	"SZEDER Gábor" <szeder@ira.uka.de>, "Jeff King" <peff@peff.net>
Subject: [PATCH v3 2/2] Handle more file writes correctly in shared repos
Date: Mon, 11 Jan 2016 19:35:54 +0100 (CET)	[thread overview]
Message-ID: <cfac7c2f2bfc8ae72c003899619d47fe856fd1e8.1452537321.git.johannes.schindelin@gmx.de> (raw)
In-Reply-To: <cover.1452537321.git.johannes.schindelin@gmx.de>

In shared repositories, we have to be careful when writing files whose
permissions do not allow users other than the owner to write them.

In particular, we force the marks file of fast-export and the FETCH_HEAD
when fetching to be rewritten from scratch.

This commit does not touch the following users of fopen() that want to
write files:

- git am, when splitting mails (git-am correctly cleans up its directory
  after finishing, so there is no need to share those files between users)

- git apply, when writing rejected hunks (to be conservative, as it is not
  clear whether to write those files in shared mode or not)

- git fsck, when writing lost&found blobs (to be conservative, as it is
  not clear whether to write those files in shared mode or not)

- git merge-file, when writing merged files (when Git itself calls
  merge-file, the file in question was already there, with shared
  permissions).

- git submodule clone, when writing the .git file, because the file will
  not be overwritten

- git_terminal_prompt() in compat/terminal.c, because it is not writing to
  a file at all

- git diff --output, because the output file is clearly not intended to be
  shared between the users of the current repository

- git fast-import, when writing a crash report, because the reports' file
  names are unique due to an embedded process ID

- mailinfo() in mailinfo.c, because the output is clearly not intended to
  be shared between the users of the current repository

- check_or_regenerate_marks() in remote-testsvn.c, because this is only
  used for Git's internal testing

- git rerere, when writing resolved files, because the files in question
  were already written with the correct permissions

Note that this patch does not touch callers of write_file() and
write_file_gently(), which would benefit from the same scrutiny as to
usage in shared repositories. Most notable users: branch, daemon,
submodule & worktree, and a worrisome call in transport.c when updating
one ref (which ignores the shared flag).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/fast-export.c | 2 +-
 builtin/fetch.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index d9ac5d8..2471297 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -880,7 +880,7 @@ static void export_marks(char *file)
 	FILE *f;
 	int e = 0;
 
-	f = fopen(file, "w");
+	f = fopen_for_writing(file);
 	if (!f)
 		die_errno("Unable to open marks file %s for writing.", file);
 
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 586840d..33f04c1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -840,7 +840,7 @@ static void check_not_current_branch(struct ref *ref_map)
 static int truncate_fetch_head(void)
 {
 	const char *filename = git_path_fetch_head();
-	FILE *fp = fopen(filename, "w");
+	FILE *fp = fopen_for_writing(filename);
 
 	if (!fp)
 		return error(_("cannot open %s: %s\n"), filename, strerror(errno));
-- 
2.6.3.windows.1.300.g1c25e49

  parent reply	other threads:[~2016-01-11 18:36 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-19 18:21 [PATCH] commit: ensure correct permissions of the commit message Johannes Schindelin
2015-12-20  7:45 ` Jeff King
2015-12-20 14:21   ` Johannes Schindelin
2015-12-20 22:57     ` Torsten Bögershausen
2015-12-30 14:57       ` Johannes Schindelin
2015-12-21  1:31   ` Junio C Hamano
2015-12-21  6:59     ` Jeff King
2015-12-21 17:22       ` Junio C Hamano
2015-12-30 14:50         ` Johannes Schindelin
2015-12-30 22:56           ` Junio C Hamano
2016-01-01 15:04             ` Johannes Schindelin
2016-01-04 18:34               ` Junio C Hamano
2016-01-05 12:52                 ` Johannes Schindelin
2016-01-05 19:39                   ` Junio C Hamano
2016-01-06  8:20                     ` Johannes Schindelin
2016-01-06  8:23                       ` Jeff King
2016-01-06  8:50                         ` Johannes Schindelin
2016-01-15  1:12     ` SZEDER Gábor
2016-01-15  1:29       ` Junio C Hamano
2016-01-15  6:51         ` Johannes Schindelin
2016-01-15 10:51         ` SZEDER Gábor
2016-01-15 12:18           ` Johannes Schindelin
2016-01-06 13:09 ` [PATCH v2 0/2] Correctly handle transient files in shared repositories Johannes Schindelin
2016-01-06 13:09   ` [PATCH v2 1/2] commit: allow editing the commit message even in shared repos Johannes Schindelin
2016-01-07 12:41     ` Jeff King
2016-01-07 21:35       ` Junio C Hamano
2016-01-06 13:09   ` [PATCH v2 2/2] Handle more file writes correctly " Johannes Schindelin
2016-01-07 12:46     ` Jeff King
2016-01-08 16:04       ` Johannes Schindelin
2016-01-07 21:52     ` Junio C Hamano
2016-01-08 16:05       ` Johannes Schindelin
2016-01-08 17:59         ` Junio C Hamano
2016-01-11  9:28           ` Johannes Schindelin
2016-01-11 15:57             ` Junio C Hamano
2016-01-11 17:06               ` Junio C Hamano
2016-01-11 18:35   ` [PATCH v3 0/2] Correctly handle transient files in shared repositories Johannes Schindelin
2016-01-11 18:35     ` [PATCH v3 1/2] commit: allow editing the commit message even in shared repos Johannes Schindelin
2016-01-11 18:35     ` Johannes Schindelin [this message]
2016-01-11 20:22     ` [PATCH v3 0/2] Correctly handle transient files in shared repositories Jeff King
2016-01-11 21:12     ` Junio C Hamano
2016-01-11 21:22       ` Junio C Hamano
2016-01-11 21:38         ` Jeff King
2016-01-11 21:54           ` Junio C Hamano
2016-01-11 22:06             ` Jeff King
2016-01-12  8:05               ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cfac7c2f2bfc8ae72c003899619d47fe856fd1e8.1452537321.git.johannes.schindelin@gmx.de \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=szeder@ira.uka.de \
    --cc=yoh@onerussian.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).