diff mbox

[libgfortran,committed] PR 64770 Segfault when trying to open existing file with status="new"

Message ID CAO9iq9HTu5QU_C=MmcB1HxQT6pRcfwR0iTMqN=we5Wt8LsF_nQ@mail.gmail.com
State New
Headers show

Commit Message

Janne Blomqvist Jan. 24, 2015, 9:56 p.m. UTC
Hi,

the attached patch fixes PR 64770, by checking whether a string is a
null pointer before calling strdup() on it. Committed r220086 as
obvious.

libgfortran ChangeLog:

2015-01-24  Janne Blomqvist  <jb@gcc.gnu.org>

    PR libfortran/64770
    * io/unit.c (filename_from_unit): Check that u->filename != NULL
    before calling strdup.

testsuite ChangeLog:

2015-01-24  Janne Blomqvist  <jb@gcc.gnu.org>

    PR libfortran/64770
    * gfortran.dg/open_new_segv.f90: New test.

Comments

Andreas Schwab Jan. 25, 2015, 8:50 a.m. UTC | #1
Janne Blomqvist <blomqvist.janne@gmail.com> writes:

>     PR libfortran/64770
>     * gfortran.dg/open_new_segv.f90: New test.

At line 9 of file /usr/local/gcc/gcc-20150125/gcc/testsuite/gfortran.dg/open_new_segv.f90 (unit = 99)
Fortran runtime error: File 'pr64770test.dat' already exists
FAIL: gfortran.dg/open_new_segv.f90   -O0  execution test

Andreas.
diff mbox

Patch

diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c
index e168d32..687f507 100644
--- a/libgfortran/io/unit.c
+++ b/libgfortran/io/unit.c
@@ -829,7 +829,7 @@  filename_from_unit (int n)
     }

   /* Get the filename.  */
-  if (u != NULL)
+  if (u != NULL && u->filename != NULL)
     return strdup (u->filename);
   else
     return (char *) NULL;