]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR 61187 Fix use of uninitialized data.
authorJanne Blomqvist <jb@gcc.gnu.org>
Fri, 16 May 2014 20:42:56 +0000 (23:42 +0300)
committerJanne Blomqvist <jb@gcc.gnu.org>
Fri, 16 May 2014 20:42:56 +0000 (23:42 +0300)
2014-05-16  Janne Blomqvist  <jb@gcc.gnu.org>

Backport from trunk:
PR libfortran/61187
* io/unix.c (raw_close): Check if s->fd is -1.
(fd_to_stream): Check return value of fstat(), handle error.

From-SVN: r210529

libgfortran/ChangeLog
libgfortran/io/unix.c

index 514ff6216d45e7d3ba9aaf232de0293bdb125d49..75805d2bbcf4f31b2f2942b47429259afb8a18bd 100644 (file)
@@ -1,3 +1,10 @@
+2014-05-16  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       Backport from trunk:
+       PR libfortran/61187
+       * io/unix.c (raw_close): Check if s->fd is -1.
+       (fd_to_stream): Check return value of fstat(), handle error.
+
 2014-05-04  Janne Blomqvist  <jb@gcc.gnu.org>
 
        Backport from 4.9
index 8421451e78c2dfce994360eee68af341fa7a9c99..31c4f69befc7835d6fd231b23db53e7710314feb 100644 (file)
@@ -392,7 +392,9 @@ raw_close (unix_stream * s)
 {
   int retval;
   
-  if (s->fd != STDOUT_FILENO
+  if (s->fd == -1)
+    retval = -1;
+  else if (s->fd != STDOUT_FILENO
       && s->fd != STDERR_FILENO
       && s->fd != STDIN_FILENO)
     retval = close (s->fd);
@@ -961,7 +963,15 @@ fd_to_stream (int fd)
 
   /* Get the current length of the file. */
 
-  fstat (fd, &statbuf);
+  if (fstat (fd, &statbuf) == -1)
+    {
+      s->st_dev = s->st_ino = -1;
+      s->file_length = 0;
+      if (errno == EBADF)
+       s->fd = -1;
+      raw_init (s);
+      return (stream *) s;
+    }
 
   s->st_dev = statbuf.st_dev;
   s->st_ino = statbuf.st_ino;