Added O_EXCL call to open is tmp == 1
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@378 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
diff --git a/files.c b/files.c
index bc76729..029217c 100644
--- a/files.c
+++ b/files.c
@@ -335,10 +335,17 @@
return -1;
else if (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(st.st_mode)) {
- /* Open the file and truncate it. Trust the symlink. */
- if ((fd = open(realname, O_WRONLY | O_CREAT | O_TRUNC,
+ /* If tmp is set, use O_EXCL, more security, YAY! */
+ if (tmp)
+ fd = open(realname, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH |
- S_IWOTH)) == -1) {
+ S_IWOTH);
+ else
+ fd = open(realname, O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH |
+ S_IWOTH);
+ /* Open the file and truncate it. Trust the symlink. */
+ if (fd == -1) {
if (ISSET(TEMP_OPT)) {
UNSET(TEMP_OPT);
return do_writeout(1);