]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/54878 (libgfortran issues found by the Coverity scanner)
authorTobias Burnus <burnus@net-b.de>
Wed, 10 Oct 2012 18:42:34 +0000 (20:42 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Wed, 10 Oct 2012 18:42:34 +0000 (20:42 +0200)
2012-10-10  Tobias Burnus  <burnus@net-b.de>

PR fortran/54878
* io/unix.c (tempfile_open): Set umask before calling mkstemp.

From-SVN: r192325

libgfortran/ChangeLog
libgfortran/io/unix.c

index 74d6294b39dacb611032522a60bfaeb184423b3b..d52648688f7fc67e2e56fb45b8db73ec28187e41 100644 (file)
@@ -1,3 +1,8 @@
+2012-10-10  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/54878
+       * io/unix.c (tempfile_open): Set umask before calling mkstemp.
+
 2012-10-06  Janne Blomqvist  <jb@gcc.gnu.org>
 
        * configure.ac: Check for presence of secure_getenv.
index 805d4bbd205f906825e9ceb83d2b6374bc855636..9d2e9d850879979e73331d60e26f095ffb0bce3f 100644 (file)
@@ -1051,6 +1051,9 @@ tempfile_open (const char *tempdir, char **fname)
 {
   int fd;
   const char *slash = "/";
+#if defined(HAVE_UMASK) && defined(HAVE_MKSTEMP)
+  mode_t mode_mask;
+#endif
 
   if (!tempdir)
     return -1;
@@ -1072,8 +1075,17 @@ tempfile_open (const char *tempdir, char **fname)
   snprintf (template, tempdirlen + 23, "%s%sgfortrantmpXXXXXX", 
            tempdir, slash);
 
+#ifdef HAVE_UMASK
+  /* Temporarily set the umask such that the file has 0600 permissions.  */
+  mode_mask = umask (S_IXUSR | S_IRWXG | S_IRWXO);
+#endif
+
   fd = mkstemp (template);
 
+#ifdef HAVE_UMASK
+  (void) umask (mode_mask);
+#endif
+
 #else /* HAVE_MKSTEMP */
   fd = -1;
   int count = 0;