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

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: r210527

libgfortran/ChangeLog
libgfortran/io/unix.c

index ed26a4d70772649a0e60b76f9e1186cd1b61470b..f9287bd0e85aee0d9766269669592ed646a1b18b 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-16  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       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-12  Janne Blomqvist  <jb@gcc.gnu.org>
 
        PR libfortran/61035
index 34c2d0cad163f8ef30c93ebf1b62d09e06cbb208..76ed84effbf6348d0faf7aa753b398e732ee6281 100644 (file)
@@ -412,7 +412,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);
@@ -1003,7 +1005,15 @@ fd_to_stream (int fd, bool unformatted)
 
   /* 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;