summaryrefslogtreecommitdiff
path: root/libgfortran/io
diff options
context:
space:
mode:
authorjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-16 20:37:13 +0000
committerjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-16 20:37:13 +0000
commit7b89cd4f3f63aba6e1bf12dbe1e7774a36eba883 (patch)
treee2b9590673b3978f49350f9440fe3aa32bc1ddff /libgfortran/io
parentde7af99e93eaddf123593b71294cce26559a9df6 (diff)
downloadgcc-7b89cd4f3f63aba6e1bf12dbe1e7774a36eba883.tar.gz
PR 61187 Fix use of uninitialized memory.
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210527 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/io')
-rw-r--r--libgfortran/io/unix.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 34c2d0cad16..76ed84effbf 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -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;