aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-07-28 10:34:41 -0700
committerJunio C Hamano <gitster@pobox.com>2016-07-28 10:34:41 -0700
commitd0b6966e3dc0a1aca8b7aa89dd0f95cda50d21f2 (patch)
tree180fba4d17eac6d8cdc52d80ecc99edae01cd2ab
parentc97268c822077ba414f90f6ba357fab170bb3986 (diff)
parentdeb9c1575c456b9d12ff05fdd2bec516dfb34ae4 (diff)
downloadgit-d0b6966e3dc0a1aca8b7aa89dd0f95cda50d21f2.tar.gz
git-d0b6966e3dc0a1aca8b7aa89dd0f95cda50d21f2.tar.xz
Merge branch 'rs/notes-merge-no-toctou'
"git notes merge" had a code to see if a path exists (and fails if it does) and then open the path for writing (when it doesn't). Replace it with open with O_EXCL. * rs/notes-merge-no-toctou: notes-merge: use O_EXCL to avoid overwriting existing files
-rw-r--r--notes-merge.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/notes-merge.c b/notes-merge.c
index 1b58a14eb..97fc42f64 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -298,12 +298,8 @@ static void write_buf_to_worktree(const unsigned char *obj,
char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", sha1_to_hex(obj));
if (safe_create_leading_directories_const(path))
die_errno("unable to create directory for '%s'", path);
- if (file_exists(path))
- die("found existing file at '%s'", path);
- fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0666);
- if (fd < 0)
- die_errno("failed to open '%s'", path);
+ fd = xopen(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
while (size > 0) {
long ret = write_in_full(fd, buf, size);