Skip to content

Commit 743fba8

Browse files
committed
Merge branch 'rs/notes-merge-no-toctou' into maint
"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
2 parents a52fb9b + deb9c15 commit 743fba8

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

notes-merge.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,8 @@ static void write_buf_to_worktree(const unsigned char *obj,
298298
char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", sha1_to_hex(obj));
299299
if (safe_create_leading_directories_const(path))
300300
die_errno("unable to create directory for '%s'", path);
301-
if (file_exists(path))
302-
die("found existing file at '%s'", path);
303301

304-
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0666);
305-
if (fd < 0)
306-
die_errno("failed to open '%s'", path);
302+
fd = xopen(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
307303

308304
while (size > 0) {
309305
long ret = write_in_full(fd, buf, size);

0 commit comments

Comments
 (0)