PR fortran/95104 - Segfault on a legal WAIT statement
authorHarald Anlauf <anlauf@gmx.de>
Tue, 26 May 2020 21:29:52 +0000 (23:29 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 26 May 2020 21:29:52 +0000 (23:29 +0200)
Referencing a unit in a WAIT statement that has not been opened before
resulted in a NULL pointer dereference.  Check for this condition.

2020-05-26  Harald Anlauf  <anlauf@gmx.de>

libgfortran/
PR libfortran/95104
* io/transfer.c (st_wait_async): Do not dereference NULL pointer.

gcc/testsuite/
PR libfortran/95104
* gfortran.dg/pr95104.f90: New test.

Co-Authored-By: Steven G. Kargl <kargl@gcc.gnu.org>
gcc/testsuite/gfortran.dg/pr95104.f90 [new file with mode: 0644]
libgfortran/io/transfer.c

diff --git a/gcc/testsuite/gfortran.dg/pr95104.f90 b/gcc/testsuite/gfortran.dg/pr95104.f90
new file mode 100644 (file)
index 0000000..20bdd91
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do run }
+! PR libfortran/95104 - Segfault on a legal WAIT statement
+
+program test
+  wait (10, iostat=ios)
+  if (ios /= 0) stop 1
+  close (10)
+end program test
index d071c1ce915cc7222f66a70e80848b6671c1c5b7..cd51679ff46649c5880640882506bbaadcfdd1ea 100644 (file)
@@ -4500,7 +4500,7 @@ void
 st_wait_async (st_parameter_wait *wtp)
 {
   gfc_unit *u = find_unit (wtp->common.unit);
-  if (ASYNC_IO && u->au)
+  if (ASYNC_IO && u && u->au)
     {
       if (wtp->common.flags & IOPARM_WAIT_HAS_ID)
        async_wait_id (&(wtp->common), u->au, *wtp->id);