This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.



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;


-- 
Janne Blomqvist


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]