This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, libgfortran, committed] PR 64770 Segfault when trying to open existing file with status="new"
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Fortran List <fortran at gcc dot gnu dot org>
- Date: Sat, 24 Jan 2015 23:56:01 +0200
- Subject: [PATCH, libgfortran, committed] PR 64770 Segfault when trying to open existing file with status="new"
- Authentication-results: sourceware.org; auth=none
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