]> git.eshelyaron.com Git - emacs.git/commitdiff
* keyboard.c (Fopen_dribble_file): Avoid some races.
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Apr 2014 21:54:27 +0000 (14:54 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Apr 2014 21:54:27 +0000 (14:54 -0700)
Fixes: debbugs:17187
src/ChangeLog
src/keyboard.c

index cb17738d13946811d52a7613c5ac63c89d48c38e..2d7307412b24c082d8af490d1e75126e40aea54d 100644 (file)
@@ -1,3 +1,7 @@
+2014-04-12  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * keyboard.c (Fopen_dribble_file): Avoid some races.  (Bug#17187)
+
 2014-04-12  Eli Zaretskii  <eliz@gnu.org>
 
        * xdisp.c (move_it_by_lines): If a large portion of buffer text is
index f74ba0ee58129cee6dcbc4b6d455cbaa00dbe207..a66054f153fc96638c15915927cc69191fa646c3 100644 (file)
@@ -10088,15 +10088,9 @@ This may include sensitive information such as passwords.  */)
     {
       int fd;
       file = Fexpand_file_name (file, Qnil);
-      /* This isn't robust, since eg file could be created after we
-         check whether it exists but before emacs_open.
-         Feel free to improve it, but this is not critical.  (Bug#17187)  */
-      if (! NILP (Ffile_exists_p (file)))
-        {
-          if (chmod (SSDATA (file), 0600) < 0)
-            report_file_error ("Doing chmod", file);
-        }
-      fd = emacs_open (SSDATA (file), O_WRONLY | O_CREAT | O_TRUNC, 0600);
+      fd = emacs_open (SSDATA (file), O_WRONLY | O_CREAT | O_EXCL, 0600);
+      if (fd < 0 && errno == EEXIST && unlink (SSDATA (file)) == 0)
+       fd = emacs_open (SSDATA (file), O_WRONLY | O_CREAT | O_EXCL, 0600);
       dribble = fd < 0 ? 0 : fdopen (fd, "w");
       if (dribble == 0)
        report_file_error ("Opening dribble", file);