]> git.wh0rd.org Git - nano.git/commitdiff
Added O_EXCL call to open is tmp == 1
authorChris Allegretta <chrisa@asty.org>
Mon, 4 Dec 2000 03:31:39 +0000 (03:31 +0000)
committerChris Allegretta <chrisa@asty.org>
Mon, 4 Dec 2000 03:31:39 +0000 (03:31 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@378 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
files.c

index 69758ff9c9a223f78f6f17a7a78f674b3b401935..c8ec5c5f79c35af12b1864a1baddfbed1b7273c6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
 CVS code -
+- files.c:
+  write_file()
+       - Added O_EXCL to open call if tmp is set, more security which hopefully
+         fixes any remaining security issues.
+
 nano 0.9.22 - 12/02/2000
 - General
        - Username tab completion code, and cleaned up existing tabcomp
diff --git a/files.c b/files.c
index bc76729ab5133dd12a8939f1e364b908ab2fd577..029217cc8df60318ff1981542f3bf6da51998a99 100644 (file)
--- a/files.c
+++ b/files.c
@@ -335,10 +335,17 @@ int write_file(char *name, int tmp)
         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);
+       else
+           fd = open(realname, O_WRONLY | O_CREAT | O_TRUNC,
                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH |
-                      S_IWOTH)) == -1) {
+                      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);