From 7165d8f1916979828be6e913a2a0d19d2923ffd0 Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Sat, 24 Jan 2015 23:52:34 +0200 Subject: [PATCH] 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 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/open_new_segv.f90 | 10 ++++++++++ libgfortran/ChangeLog | 6 ++++++ libgfortran/io/unit.c | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/open_new_segv.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8b3dfc41b64..b342a33211d 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 00000000000..56cd1afd9b5 --- /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 04f85c7c46c..e228a677105 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 e168d328665..687f5076a5b 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; -- 2.30.2