From 3d13b786617560179ad6833d01d2c28fe733127c Mon Sep 17 00:00:00 2001 From: Kyrylo Tkachov Date: Tue, 18 Sep 2018 09:02:14 +0000 Subject: [PATCH] [libgfortran] Fix uninitialized variable use in fallback_access Backport from trunk 2018-09-14 Kyrylo Tkachov * io/unix.c (fallback_access): Avoid calling close on uninitialized file descriptor. From-SVN: r264384 --- libgfortran/ChangeLog | 8 ++++++++ libgfortran/io/unix.c | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index afe561b2162d..004b25865b61 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,11 @@ +2018-09-18 Kyrylo Tkachov + + Backport from trunk + 2018-09-14 Kyrylo Tkachov + + * io/unix.c (fallback_access): Avoid calling close on + uninitialized file descriptor. + 2018-06-22 Jakub Jelinek Backported from mainline diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index bb9bc9a5c125..993797e6d1f8 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -149,13 +149,21 @@ fallback_access (const char *path, int mode) { int fd; - if ((mode & R_OK) && (fd = open (path, O_RDONLY)) < 0) - return -1; - close (fd); + if (mode & R_OK) + { + if ((fd = open (path, O_RDONLY)) < 0) + return -1; + else + close (fd); + } - if ((mode & W_OK) && (fd = open (path, O_WRONLY)) < 0) - return -1; - close (fd); + if (mode & W_OK) + { + if ((fd = open (path, O_WRONLY)) < 0) + return -1; + else + close (fd); + } if (mode == F_OK) { -- 2.47.2