]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(save_stdin): Open temporary file exclusively, to
authorJim Meyering <jim@meyering.net>
Wed, 11 Mar 1998 11:54:11 +0000 (11:54 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 11 Mar 1998 11:54:11 +0000 (11:54 +0000)
foil a common denial-of-service attack.
From Paul Eggert.

src/tac.c

index f55fb6ffb2067f920c43d69e1930e5ee4f29737f..fcd8e547c8a7eb6e1d2c8d3d7b4ad40908001be2 100644 (file)
--- a/src/tac.c
+++ b/src/tac.c
@@ -418,7 +418,7 @@ save_stdin (FILE **g_tmp, char **g_tempfile)
   sprintf (template, "%s/tacXXXXXX", tempdir);
   tempfile = mktemp (template);
 
-  fd = creat (tempfile, 0600);
+  fd = open (tempfile, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600);
   if (fd == -1 || (tmp = fdopen (fd, "rw")) == NULL)
     error (EXIT_FAILURE, errno, "%s", tempfile);
   tmp = fdopen (fd, "rw");