]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fortran: Fix runtime segfault closing negative unit
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 13 Apr 2025 02:51:23 +0000 (19:51 -0700)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 13 Apr 2025 15:39:32 +0000 (08:39 -0700)
commitee6173800ed1f9b653a85019ad2fa8e6d883823a
treed55f9b7e457d6e53f449cace2f336f870734b1dc
parent5869a881442aa4214d5deed7cfe0d352bcca1fd4
Fortran: Fix runtime segfault closing negative unit

When closing a UNIT with an invalid negative unit
number, a segfault ensued. This patch adds checks
for these conditions and issues errors.

PR libfortran/119502

libgfortran/ChangeLog:

* io/close.c (st_close): Issue an error and avoid
calling close_share when there is no stream assigned.
* io/open.c (st_open): If there is no stream assigned
to the unit, unlock the unit and issue an error.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr119502.f90: New test.
gcc/testsuite/gfortran.dg/pr119502.f90 [new file with mode: 0644]
libgfortran/io/close.c
libgfortran/io/open.c