From: Janne Blomqvist Date: Sat, 24 Jan 2015 21:52:34 +0000 (+0200) Subject: PR libfortran/64770 Segfault when trying to open existing file with status="new". X-Git-Tag: releases/gcc-5.1.0~1396 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7165d8f1916979828be6e913a2a0d19d2923ffd0;p=thirdparty%2Fgcc.git PR libfortran/64770 Segfault when trying to open existing file with status="new". libgfortran ChangeLog: 2015-01-24 Janne Blomqvist PR libfortran/64770 * io/unit.c (filename_from_unit): Check that u->filename != NULL before calling strdup. testsuite ChangeLog: 2015-01-24 Janne Blomqvist PR libfortran/64770 * gfortran.dg/open_new_segv.f90: New test. From-SVN: r220086 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8b3dfc41b64c..b342a33211d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-01-24 Janne Blomqvist + + PR libfortran/64770 + * gfortran.dg/open_new_segv.f90: New test. + 2015-01-24 Oleg Endo PR target/49263 diff --git a/gcc/testsuite/gfortran.dg/open_new_segv.f90 b/gcc/testsuite/gfortran.dg/open_new_segv.f90 new file mode 100644 index 000000000000..56cd1afd9b52 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/open_new_segv.f90 @@ -0,0 +1,10 @@ +! { dg-do run } +! PR 64770 SIGSEGV when trying to open an existing file with status="new" +program pr64770 + implicit none + ! Make sure pr64770test.dat exists + open(99, file="pr64770test.dat", status="replace") + close(99) + open(99, file="pr64770test.dat", access="stream", form="unformatted", & + status="new") +end program pr64770 diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 04f85c7c46cd..e228a677105c 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2015-01-24 Janne Blomqvist + + PR libfortran/64770 + * io/unit.c (filename_from_unit): Check that u->filename != NULL + before calling strdup. + 2015-01-22 Jerry DeLisle PR libgfortran/61933 diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index e168d328665c..687f5076a5ba 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;