Kyrill Tkachov
2018-09-14 08:06:08 UTC
Hi all,
I've been tracking down a bug in a Fortran program on a newlib target and it boils down to fallback_access doing something bad.
The unconditional calls to close cause havoc when open doesn't get called due to the short-circuiting in the if-statement above
because the fd is uninitialised. In my environment GCC ends up calling close on file descriptor 0, thus trying to close stdin.
This patch tightens up the calling so that close is called only when the corresponding open call succeeded.
With this my runtime failure disappears.
Bootstrapped and tested on aarch64-none-linux-gnu.
Though that doesn't exercise this call I hope it's an obviously correct change.
Ok for trunk and the branches?
Thanks,
Kyrill
2018-09-14 Kyrylo Tkachov <***@arm.com>
* io/unix.c (fallback_access): Avoid calling close on
uninitialized file descriptor.
I've been tracking down a bug in a Fortran program on a newlib target and it boils down to fallback_access doing something bad.
The unconditional calls to close cause havoc when open doesn't get called due to the short-circuiting in the if-statement above
because the fd is uninitialised. In my environment GCC ends up calling close on file descriptor 0, thus trying to close stdin.
This patch tightens up the calling so that close is called only when the corresponding open call succeeded.
With this my runtime failure disappears.
Bootstrapped and tested on aarch64-none-linux-gnu.
Though that doesn't exercise this call I hope it's an obviously correct change.
Ok for trunk and the branches?
Thanks,
Kyrill
2018-09-14 Kyrylo Tkachov <***@arm.com>
* io/unix.c (fallback_access): Avoid calling close on
uninitialized file descriptor.